package cn.lfd.web.controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
//利用apache文件上传组件进行文件上传
public class UploadServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String savepath = this.getServletContext().getRealPath("/WEB-INF/upload");//得到WEB-INF/upload代表的真实路径
try {
D
用apache文件上传组件commons-io-2.4.jar commons-fileupload-1.2.1.jar进行文件上传
最新推荐文章于 2024-04-30 09:28:00 发布
本文介绍了如何使用Apache的commons-fileupload和commons-io库进行文件上传。通过创建Servlet,设置了文件上传路径、大小限制和编码,解决了文件名乱码问题,并采用UUID和hashCode算法处理文件存储,确保文件唯一性和目录分散,同时强调了上传安全和资源清理。
摘要由CSDN通过智能技术生成