关于获取上传文件为空的问题?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于获取上传文件为空的问题?相关的知识,希望对你有一定的参考价值。
/*
* 上传文档
*/
public void Upload() throws IOException
HttpServletRequest request=ServletActionContext.getRequest();
HttpServletResponse response=ServletActionContext.getResponse();
String savePath =ServletActionContext.getServletContext()
.getRealPath("");
savePath = savePath + "/upload/";
File f1 = new File(savePath);
System.out.println(savePath);
if (!f1.exists())
f1.mkdirs();
DiskFileItemFactory fac = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setHeaderEncoding("utf-8");
List fileList = null;
try
fileList = upload.parseRequest(request);
catch (FileUploadException ex)
return;
Iterator<FileItem> it = fileList.iterator();
String name = "";
String extName = "";
while (it.hasNext())
FileItem item = it.next();
if (!item.isFormField())
name = item.getName();
System.out.println(name);
long size = item.getSize();
String type = item.getContentType();
System.out.println(size + "字节" + " " + type);
if (name == null || name.trim().equals(""))
continue;
// 扩展名格式:
if (name.lastIndexOf(".") >= 0)
extName = name.substring(name.lastIndexOf("."));
File file = null;
try catch中的fileList总是空的,不知道该咋解决,请各位高手帮忙
以上是关于关于获取上传文件为空的问题?的主要内容,如果未能解决你的问题,请参考以下文章
flask上传文件时request.files为空的解决办法