
im using a page which is in JSP. i have some text boxes and one upload button. i want to load the file itself when i click the submit button. im using enctype="multipart/form-data" in this form. i also using the commons-fileupload-1.2.2.jar file for getting the uploaded value. but the problem is the uploaded file is not stored in the prefered folder. i printed the path it shows correctly.
here the code,
the form is post method, and enctype="multipart/form-data"
here the code,
boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { out.print("No multipart");
} 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(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (!item.isFormField()) { try { String itemName = item.getName(); File savedFile = new File(config.getServletContext().getRealPath("/")+"emp_image\image\"+itemName); item.write(savedFile);
out.print("<br>"+savedFile); } catch (Exception e) { e.printStackTrace(); } } else { String name = item.getFieldName(); String value = item.getString(); }
the savedFile prints the path. and i also created the required folders. but the uploaded image is not present in the folder.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.