By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,115 Members | 808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,115 IT Pros & Developers. It's quick & easy.

my code of uploading picture

P: 2
Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.util.List" %>
  2.    <%@ page import="java.util.Iterator" %>
  3.    <%@ page import="java.io.File" %>
  4.    <%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
  5.    <%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
  6.    <%@ page import="org.apache.commons.fileupload.*"%>
  7.    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  8.    <%@ page import="np.com.ntech.adbl.check.*"%>
  9.  
  10.  
  11.    <center><table border="2">
  12.         <tr><td><h1>Your files  uploaded </h1></td></tr>
  13.    <%
  14.    Image image=new Image();
  15.    String randomNo="";
  16.    String checkNo="";
  17.          boolean isMultipart = ServletFileUpload.isMultipartContent(request);
  18.   if (!isMultipart) {
  19.    } else {
  20.    FileItemFactory factory = new DiskFileItemFactory();
  21.        ServletFileUpload upload = new ServletFileUpload(factory);
  22.        List items = null;
  23.  
  24.        try {
  25.            items = upload.parseRequest(request);
  26.        } catch (FileUploadException e) {
  27.            e.printStackTrace();
  28.        }
  29.        Iterator itr = items.iterator();
  30.        while (itr.hasNext()) {
  31.        FileItem item = (FileItem) itr.next();
  32.        if (item.isFormField()) {
  33.        String name = item.getFieldName();
  34.        String value = item.getString();
  35.  
  36.                     if((name.equals("checkNo"))&&(name!=null)){
  37.                     image.setCheckNo(value);    
  38.                     checkNo=value;
  39.                     }
  40.                     /*if(image.isExist()) { 
  41.                     errMap.put("name","Name already exists");
  42.                     isValid=true;                                      
  43.                     }    */      
  44.                     if((name.equals("bankCd"))&&(name!=null)){
  45.                     image.setDestBank(value);    
  46.                     }
  47.                     if((name.equals("branchCd"))&&(name!=null)){
  48.                     image.setDestBranch(value);    
  49.                     }
  50.                     if((name.equals("amount"))&&(name!=null)){
  51.                     image.setAmount(value);    
  52.                     }
  53.                     if((name.equals("remarks"))&&(name!=null)){
  54.                     image.setRemarks(value);    
  55.                     }
  56.                     if((name.equals("radNo"))&&(name!=null)){
  57.                     image.setRadNo(value);
  58.                     randomNo=value;
  59.                     }
  60.                     if((name.equals("checkType"))&&(name!=null)){
  61.                     image.setCheckType(value);    
  62.                     }
  63.                     if((name.equals("accountHolder"))&&(name!=null)){
  64.                     image.setAccountHolder(value);    
  65.                     }      
  66.                     if((name.equals("payee"))&&(name!=null)){
  67.                     image.setPayee(value);    
  68.                     }           
  69.                     if((name.equals("payeeAccountNo"))&&(name!=null)){
  70.                     image.setPayeeAccountNo(value);    
  71.                     }          
  72.                     if((name.equals("accountNo"))&&(name!=null)){
  73.                     image.setAccountNo(value);    
  74.                     }           
  75.  
  76.  
  77.        } else {
  78.              try {
  79.                String fileName=item.getFieldName();
  80.                String itemName = item.getName();
  81.                 int IndexOf = itemName.indexOf("."); 
  82.                 String domain = itemName.substring(IndexOf);
  83.                 //String Name = randomNo.concat("_").concat(fileName).concat(domain);
  84.                  String Name=fileName.concat(checkNo).concat("_").concat(randomNo).concat(domain);
  85.                  if (fileName.equals("front")&&(fileName!=null)){
  86.                  image.setImageName(Name)  ;
  87.                }
  88.                if (fileName.equals("back")&&(fileName!=null)){
  89.                      image.setImageName1(Name)  ;
  90.                    }
  91.                File savedFile = new File(config.getServletContext().getRealPath("/")+"uploadedFiles/"+Name);
  92.                //File savedFile = new File(config.getServletContext().getRealPath("/")+"uploadedFiles/"+Name2);
  93.              item.write(savedFile); 
  94.              out.println("<tr><td><b>Your file has been saved at the location:</b></td></tr><tr><td><b>"+config.getServletContext().getRealPath("/")+"uploadedFiles"+"\\"+itemName+" </td></tr>");
  95.           %>
  96.            <% } catch (Exception e) {
  97.                e.printStackTrace();
  98.            }
  99.        } 
  100.        }
  101.        image.setSrcBank(session.getAttribute("bankCd").toString());
  102.         image.setSrcBranch(session.getAttribute("branchCd").toString());
  103.         image.setUserId(session.getAttribute("userId").toString());  
  104.        image.saveCheck(session.getAttribute("name").toString());
  105.    }                           
  106.    %>
  107.     </table>
  108.     <a href="addImages.jsp">Home</a>
  109.    </center>
In above code i need the code for scaling the picture.
Please help me.
Thanks in advance !!
Jan 27 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.