Reputation: 299
i am writing a web app and i want to upload a file to the servlet. i read that i can use ServletFileUpload.parseRequest(request) it works on one computer. but when i try to run the code on another computer i get an error that the function needs RequestContext: ServletFileUpload.parseRequest(RequestContext)
on the computer that the function works with HttpServletRequest i see the function with RequestContext. but i don't use it
is there another way to upload files to servlet?
Upvotes: 5
Views: 6589
Reputation: 413
You could try:
new ServletFileUpload().parseRequest(new ServletRequestContext(request));
This change works on the latest apache tomcat (at least on 7.0.70, which I am using).
Upvotes: 6
Reputation: 1734
Make sure both environment have the same Apache fileupload jar. I'm using commons-fileupload-1.2.2 and it have both methods
ServletFileUpload.parseRequest(HttpServletRequest request) and ServletFileUpload.parseRequest(RequestContext context)
Upvotes: 0
Reputation: 1653
Have you considered using a container (eg Tomcat 7+) that implements Servlet 3.0? That version of the spec has been around for a few years, and has added an API for uploading files.
http://docs.oracle.com/javaee/6/tutorial/doc/glrbb.html
Upvotes: 0