求助commons fileupload的问题
action代码:
public String addShop(HttpServletRequest request, HttpServletResponse response, Model model) throws SysException, FileUploadException {
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
// Create a new file upload handler
// ServletFileUpload upload = new ServletFileUpload();
for(Object item:items) {
System.out.println(item);
}
return null;
}
<form action="<c:url value='/client/addShop'/>" id="addForm" name="addForm" method="post"
enctype="multipart/form-data" >
<ul>
<li>
<em>商铺图标<i></i></em>
<input type="file" name="shopLogo" id="shopLogo"/>
<div id="shopLogoError" style="color: red"></div>
</li>
<li>
<em>商铺图标<i></i></em>
<input type="file" name="shopLogo1" id="shopLogo1"/>
<div id="shopLogoError" style="color: red"></div>
</li>
<li>
<em>商铺图标<i></i></em>
<input type="file" name="shopLogo2" id="shopLogo2"/>
<div id="shopLogoError" style="color: red"></div>
</li>
<li>
<em>商铺图标<i></i></em>
<input type="file" name="shopLogo3" id="shopLogo3"/>
<div id="shopLogoError" style="color: red"></div>
</li>
</ul>
</form> --------------------编程问答-------------------- 这样在action里面获得的items为空,应该怎么解决? --------------------编程问答-------------------- 改成下面所写,我测试了 可以的
--------------------编程问答--------------------
public String addShop(HttpServletRequest request, HttpServletResponse response, Model model) throws SysException, FileUploadException {
// Check that we have a file upload request
String tempPath = "D:\" //文件上传后备份路径
File tempPath1 = new File(tempPath);
if (!tempPath1.isDirectory()) {
tempPath1.mkdir();
}
DiskFileUpload upload = new DiskFileUpload();
upload.setSizeMax(10 * 1024 * 1024);
upload.setSizeThreshold(10 * 1024);
upload.setRepositoryPath(tempPath);
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
for(Object item:items) {
System.out.println(item);
}
return null;
}
不行哦,是不是jsp页面的问题,我第一次弄不清楚。 --------------------编程问答--------------------
method="post"
这个删除
补充:Java , Web 开发