0

I referred How to upload files to server using JSP/Servlet? guide to upload the files with multipart/form-data using Servlet.

  1. Before using

    @WebServlet("/upload")

    @MultipartConfig

Annotations I am able to upload the file to the server but unable to read control field data. Now I used Annotations with my Servlet with the action control.

Problem is able to read the control field values but files is not uploading into server. Used this snippets

FileItemFactory factory = new DiskFileItemFactory();
//Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
File uploadedFile;
//Parse the request
List  items = upload.parseRequest(request);
Iterator iterator = items.iterator();
while (iterator.hasNext()) {
}

I am getting the itmes size as 0 (ZERO) when I pasre the request while uploading the file. What may be the issue in my case ?

Thanks in advance!!

Community
  • 1
  • 1
Prajwal Bhat
  • 303
  • 2
  • 5
  • 21

2 Answers2

0

The HTTP request can be parsed only once. So, If request.get<>() (request.getParameter(),request.getAttribute()) used prior to upload.parseRequest() this will not work. Make sure you are not having any such usage in your servlet (Check filters as well)

Santhosh
  • 1
  • 1
  • But in my case, I need to use `request.getParameter()` for fetching the control field value before or after the file upload. Thing I need to get upload the file as well as I need to get the control field values ? Means I cannot able to do these two functions meanwhile with the same **request** object ? – Prajwal Bhat Sep 20 '16 at 11:32
  • Can I get any solutions to achieve to perform both actions ? – Prajwal Bhat Sep 26 '16 at 05:29
0

RESOLVED!!

this resolved the file uploading with multipart/form-data and reading multiple control fields from the JSP form pages

Prajwal Bhat
  • 303
  • 2
  • 5
  • 21