2

I used Jquery file upload with backend java. Am getting

if(ServletFileUpload.isMultipartContent(request) is true.

but

List<FileItem> items = uploadHandler.parseRequest(request);

returns empty.I have not accessed request parameters before.

I google it and found change from /* to /*.action in web.xml will solve the problem. But by this change the struts2 project is not running.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
nansjames
  • 35
  • 1
  • 8

1 Answers1

1
  1. That change makes no sense, both values ( */ and /*.action) are wrong, it should be /*.

  2. You should never parse a Multipart Request by yourself, especially when there are tools out there like Apache Commons FileUpload doing it for you, most likely better than you. Quoting BalusC:

    Parsing such a stream requires precise background knowledge of how multipart form data requests are specified and structured. To create a perfect multipart parser you'll have to write a lot of code. But fortunately there's the Apache Commons FileUpload which has proven its robustness with years.

  3. Struts2 already handles that. You only need to understand how the file upload process works in Struts2.

    Try with a single file in an <s:file/> element first, then with multiple files in a <s:file/> , and finally add Blueimp's jQuery-File-Upload to the equation.

    Notice that with external libraries, it might be necessary to make small modifications, like in the case of Dropzone.js (drag and drop uploader).

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • Thanks for your information.I tried with multiple inputs and its working fine. Am trying to implement basic ui from jquery.so i added all the required js from jquery and the front end is working fine.In main.js its calling jquery-fileupload.js.Do i want to change jquery-fileupload.js according to sturts2 as like Dropzone.js? As far now multipart content is receiving in the request.Please advice me futher. – nansjames Nov 20 '14 at 15:05
  • Examine the network output: if it acts like dropzone.js, then change it as described in that answer. Struts2 don't want those [] in the multipart request. Does it work with 1 file, btw ? – Andrea Ligios Nov 20 '14 at 15:18
  • Thank you so much. I can get file in action.Its working with jquery-fileupload.js with any change.I just removed " 5000000 " from struts.xml – nansjames Nov 20 '14 at 16:47