u012528214
cool18TH
采纳率0%
2017-04-29 04:16 阅读 4.7k

文件上传upload.parseRequest(request)解析为空

JSP+servlet实现,没有用到框架
图片说明
jsp:
< form action= "${pageContext.request.contextPath}/CourseUpload"
method = "post" enctype="multipart/form-data" >

servlet:
DiskFileItemFactory factory = new DiskFileItemFactory();
String path = request.getSession().getServletContext().getRealPath("/upload");
System.out.println(path);
factory.setRepository(new File(path));
factory.setSizeThreshold(1024 * 1024);

    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(-1);

    try {
        List< FileItem> list = upload.parseRequest(request);
        System.out.println(list);
        for (FileItem item : list) {
            if (item.isFormField()) {
                realpath = item.getName();
                System.out.println(realpath);
            }else{
                realpath = item.getName();
                System.out.println(realpath);
            }
        }
    } catch (FileUploadException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • ljheee ljheee 2017-04-29 09:50

    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(-1);//去掉这行

    点赞 评论 复制链接分享

相关推荐