<context-param>
<param-name>FileUploadToServer</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>FileUploadLocalFolder</param-name>
<param-value>FILE_UPLOAD</param-value>
</context-param>
String referenceID = request.getParameter("referenceID");
String toServer = application.getInitParameter("FileUploadToServer");
if(toServer.equals("true")){
String filePath = application.getRealPath("/")+application.getInitParameter("FileUploadLocalFolder");
//建立文件工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//设置上传工厂的限制
factory.setSizeThreshold(1024 * 1024 * 20);
//创建一个上传文件的ServletFileUpload对象
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(request);
Iterator<FileItem> iter = list.iterator();
while (iter.hasNext()) {
FileItem item = iter.next();
String filename = item.getName(); //获取上传文件的名称
File outfilepath = new File(filePath); //创建文件路径
if(!outfilepath.isDirectory()){
outfilepath.mkdir();
}
fileItem.write(new File(filePath + "\\" + referenceID + "\\" +filename));
}
}