File uploads need to use the Cos.jar package. File upload the Display page index.jsp file is as follows:
<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
The form must be submitted using post, and the phrase "Multipart/form-data" must be written enctype=. The corresponding Uploadservlet.java files are as follows:
Import Java.io.File;
Import java.io.IOException;
Import java.util.Enumeration;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Com.hh.excel.ExcelData;
Import Com.oreilly.servlet.MultipartRequest; public class Uploadservlet extends HttpServlet {public void doget (HttpServletRequest request, HttpServletResponse Respo
NSE) throws Servletexception, IOException {doPost (request, response);
public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
Upload files//files uploaded, save in the C-Packing directory request.setcharacterencoding ("Utf-8");
String savedirectory = new File ("c:/"). GetAbsolutePath ();
String FilePath = "";
Maximum 500m int maxpostsize = 1 * 500 * 1024 * 1024 per file; Response is encoded as "Utf-8", and the default file name Conflict resolution strategy is implemented to upload multipartrequest multi = new Multipartrequest (Request, Savedirectory, Maxpostsize, "Utf-8 ");
Output feedback Information Enumeration files = Multi.getfilenames ();
while (Files.hasmoreelements ()) {String name = (String) files.nextelement ();
File f = multi.getfile (name);
if (f!= null) {String fileName = multi.getfilesystemname (name);
FilePath = savedirectory + "\" + fileName;
System.out.println (FilePath);
}
}
}
}