0

I have created a form in which I am using some text boxes and multiple images. Images are getting uploaded properly using below code but text box value is coming as null, reason I know because I am using enctype in form but I don't know how to resolve this. I have seen some solution on internet but by applying these solution I will have to change the image upload code, which is also an another pain because currently image upload code is working.

    String inputName = null;
   String username = null;



    String user_name = "abc1234567890@3aefaf";
    String Directory_storage = "C:\\Users\\gur29175\\Desktop\\";
    String fileSavePath_upload_dir = Directory_storage+user_name+"\\";
    String file_type = ".png";

    if (!(new File(fileSavePath_upload_dir)).exists()) 
    {
        (new File(fileSavePath_upload_dir)).mkdir();    // creates the directory if it does not exist        
    }

            boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (!isMultipart) {
        } else {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List items = null;
            try {
                items = upload.parseRequest(request);
                } catch (FileUploadException e) {
                    e.printStackTrace();
                }
            Iterator itr = items.iterator();
            int file_index = 1;

            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {
                } else {
                    try {
                    String itemName = item.getName();
                    inputName = (String)item.getFieldName(); 
                    if(inputName.equalsIgnoreCase("name"))
                    { 
            username = (String)item.getString(); 

                    }
                    File savedFile = new File(fileSavePath_upload_dir+itemName);                    
                    item.write(savedFile);  

                    File file = new File(fileSavePath_upload_dir+itemName);
                    File file2 = new File(fileSavePath_upload_dir+user_name+"_"+file_index+file_type);
                    boolean success = file.renameTo(file2);

                    } catch (Exception e) {
                    e.printStackTrace();
                }
            }
                file_index = file_index + 1;
        }
    }

out.println("UserName is:"+username); 
%>
Cœur
  • 37,241
  • 25
  • 195
  • 267
byox user
  • 55
  • 1
  • 8
  • I don't understand you. I posted code over at EE when you asked your question there. But you just ignored my comment. Why did you abandon your question? – rickz Oct 27 '15 at 02:15
  • Why did you abandon? http://stackoverflow.com/questions/33196996/multiple-image-upload-using-jsp – rickz Oct 27 '15 at 02:22
  • Hi Rickz... As per your suggestion... This time I am not using O'Reilly API.. Still facing some problem That's why I asked this question – byox user Oct 27 '15 at 10:03
  • Did you read BalusC's Apache commons code in his answer at http://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet ? Did you read the code I posted over at EE? Why do expect people to help you when you act this way? – rickz Oct 27 '15 at 14:19

0 Answers0