⽂件上传限制⽂件类型
public class FileUploadManager {
/** 允许上传的扩展名*/
public static String [] extensionPermit = {"txt", "xls", "zip"};
public FileUploadManager(Ur ur, HttpServletRequest request) throws Exception {
super();
ssion = Session();
内包装DiskFileItemFactory factory = new DiskFileItemFactory();
upload = new ServletFileUpload(factory);
SystemManager systemManager = SystemManager();
int docSize = Integer.CompanyID(), "DOCUMENT_SIZE_LIMIT").getValue());
int maxFileSize = 1024 * 1024 * docSize;
upload.tFileSizeMax(maxFileSize); // 设置单个⽂件的最⼤上传⼤⼩
upload.tSizeMax(maxFileSize + 500); // 设置整个request的最⼤⼤⼩
upload.tProgressListener(new FileUploadListener(request));
extensionPermit = CompanyID(), "DOCUMENT_EXT_LIMIT").getValue().split(",");//设置⽂件类型 files = upload.parRequest(request);
}
英语大小写字母表class QCServletFileUpload extends ServletFileUpload {
private Map textHash = new HashMap();//表单数据
bakenprivate int fileItemCount = 0;
// 重载parRequest⽅法
public List parRequest(HttpServletRequest request) throws FileUploadException {
releaList items = new ArrayList();//⽂件
try {
FileItemIterator iter = getItemIterator(request);
FileItemFactory fac = getFileItemFactory();
while (iter.hasNext()) {
环球出国
FileItemStream item = ();
FileItem fileItem = FieldName(), ContentType(), item.isFormField(), Name());
//OutputStream().clo();
if (fileItem.isFormField()) { // 处理form field
textHash.FieldName(), fileItem);小心轻放
} el if (Name() != null && Name().length() > 0) {// 处理file field
String fileExtension = Name());
if(!sionPermit, fileExtension)){
fileItemCount++;
items.add(fileItem);
}el{cph girls
throw new FileUploadException("⽂件" + Name() + "类型不⽀持.");
}自强英语
}
}
形容词的比较级和最高级
} catch (Exception e) {
e.printStackTrace();
throw new Message(), e);
}
return items;define
}
}