0

I am facing a problem while uploading a file through a java Servlet. I am using netBeans

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     //(...)
     DiskFileItemFactory  factory = new DiskFileItemFactory(); 
     factory.setSizeThreshold (maxMemSize); 
     factory.setRepository (new File ("/ home /")); 
     ServletFileUpload upload = new ServletFileUpload (factory); 
     upload.setSizeMax(maxFileSize);
     List fileItems = upload.parseRequest (request); //here it gives the error
  //data processing
}

Says: incompatible types: HttpServletRequest cannot be converted to RequestContext. Exception: java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload.parseRequest

Even if I cast it into Requestcontext , still it doesn't work But if I do the parsing context to get the following error: java.lang.ClassCastException: can not be cast to org.apache.catalina.core.ApplicationContextFacade org.apache.tomcat.util.http.fileupload.RequestContext

Thank you for your attention

user2989745
  • 149
  • 1
  • 3
  • 12
  • edited the post, added information. – user2989745 Nov 28 '13 at 14:03
  • I'm not 100% sure, but looking over some old code I had for uploading a file, I know I had to get a ServletContext object. Got this with ServletContext sc = request.getSession().getServletContext() Might be a version for RequestContext or it may be possible to case. – Chris O'Brien Nov 28 '13 at 14:07
  • Can you post the actual stack? – Taylor Nov 28 '13 at 14:28
  • I have to import some .jar or libraries to run this type of code? – user2989745 Nov 28 '13 at 15:19
  • when I wrote the code in netbeans import some libraries, thought it was necessary, but it seems no Now do import org.apache.commons.fileupload.FileItem, and gives error. Know how to care for my project this librarie? – user2989745 Nov 28 '13 at 16:12

0 Answers0