写道
//创建解析工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(this.getServletContext().getRealPath("/WEB-INF/temp")));//设置文件缓存目录
factory.setSizeThreshold(1024*1024);
//创建解析器
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
upload.setSizeMax(-1);
//解析request得到封装FileItem的list
try{
List<FileItem> list = upload.parseRequest(request);//list.size() is 0
for(int i=0; i<list.size(); i++) {
FileItem item = (FileItem)list.get(i);
if(!item.isFormField()){
String name = item.getName();
1.temp目录是在程序中设定用来做文件上传的临时目录用的.
2.被删掉后,文件大小超过设置的1024*1024字节后,就会使用到临时目录,这时如果临时目录没有,就会出现错误。
3.重新在“/WEB-INF”目录下添加上“temp”目录,错误就解决了
分享到:
相关推荐
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory;...
《Apache Commons FileUpload详解》 Apache Commons FileUpload是Java领域中处理HTTP文件上传的一个强大工具,主要用于解析HTTP请求中的多部分表单数据。在本文中,我们将深入探讨这个库的1.2.2版本,包括它的核心...
要使用Apache Commons FileUpload,首先需要将其添加到项目的类路径中。这可以通过在Maven的pom.xml文件中添加依赖或在构建路径中包含对应的JAR包来完成。以下是Maven的依赖配置示例: ```xml <groupId>commons-...
在Java Web开发中,文件上传和下载是常见的功能需求,Apache Commons FileUpload库提供了一种高效、方便的方式来处理这些操作。本教程将详细介绍如何利用commons-fileupload库来实现在Java Web应用中的文件上传和...
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory;...
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory;...
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
这篇博客文章深入讲解了如何使用Apache Commons FileUpload库来处理文件上传请求,以及相关的源码分析。 一、Apache Commons FileUpload简介 Apache Commons FileUpload是Apache软件基金会的一个开源项目,它提供了...
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
- 下载 Apache Commons FileUpload 最新版本:访问 `http://jakarta.apache.org/commons/fileupload/`。 - 创建一个 `Servlet` 或其他处理上传请求的类,继承自 `FileUploadBase`。 - 初始化 `...
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet....
import org.apache.commons.fileupload.FileUploadBase; import org.apache.commons.fileupload.servlet.ServletFileUpload; ... public void doPost(HttpServletRequest request, HttpServletResponse response) ...
Servlet { /** ...总之,Apache Commons FileUpload简化了Java中的文件上传流程,但开发者仍需关注安全性和性能优化等问题。通过合理配置和恰当的异常处理,可以构建一个稳定、安全的文件上传系统。