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.

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your information.I tried <s:file/> 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.
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 ?
Thank you so much. I can get file in action.Its working with jquery-fileupload.js with any change.I just removed " <interceptor-ref name="basicStack"/> <interceptor-ref name="fileUpload"> <param name="maximumSize">5000000</param> </interceptor-ref> " from struts.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.