使用Servlet上传文件时出错

时间:2013-11-28 12:38:46

标签: java servlets netbeans

通过java Servlet上传文件时遇到问题。我正在使用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. 例外: java.lang.RuntimeException:无法编译的源代码 - 错误的sym类型:org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload.parseRequest

即使我把它投入Requestcontext,它仍然不起作用 但是,如果我执行解析上下文以获取以下错误: java.lang.ClassCastException:无法强制转换为org.apache.catalina.core.ApplicationContextFacade org.apache.tomcat.util.http.fileupload.RequestContext

感谢您的关注

0 个答案:

没有答案