当前位置:编程学习 > JAVA >>

求助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;
}


--------------------编程问答--------------------
引用 2 楼 cjg520jie 的回复:
改成下面所写,我测试了  可以的

Java code

public String addShop(HttpServletRequest request, HttpServletResponse response, Model model) throws SysException, FileUploadException {
// Check that we have a file up……


不行哦,是不是jsp页面的问题,我第一次弄不清楚。 --------------------编程问答--------------------
引用 3 楼 xrxhb001 的回复:
引用 2 楼 cjg520jie 的回复:

改成下面所写,我测试了 可以的

Java code

public String addShop(HttpServletRequest request, HttpServletResponse response, Model model) throws SysException, FileUploadException {
// Che……


method="post"
这个删除
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,