关于springmvc的视频上传

controller里面的代码:
@RequestMapping(value = "/fileUpload2.do", method = RequestMethod.GET)

public String fileUpload2(HttpServletRequest request)

throws IllegalStateException, IOException {

System.out.println("1");
// 设置上下方文

CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(

request.getSession().getServletContext());
System.out.println("2");
// 检查form是否有enctype="multipart/form-data"

if (multipartResolver.isMultipart(request)) {

MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;

System.out.println("3");
Iterator iter = multiRequest.getFileNames();

while (iter.hasNext()) {

// 由CommonsMultipartFile继承而来,拥有上面的方法.

MultipartFile file = multiRequest.getFile(iter.next());

if (file != null) {

String fileName = "demoUpload" + file.getOriginalFilename();

String path = "E:/" + fileName;

                File localFile = new File(path);  
                file.transferTo(localFile); 
                System.out.println("4");
            }  
        }  
    }  
    return "main/homework";  
}  

    jsp页面代码:
    <form id="form" action="fileUpload2.do" method="GET" enctype="multipart/form-data">
        <table align="center" border="1" bgcolor="blue" height="300px">
         <tr align="center"><td colspan="2" align="center">
             <input type="file" name="myfile" style="height:35px; width:100px;"></td>
         </tr>
         <tr align="center"><td colspan="2" align="center" >
             <input type="submit" name="submit" value="上传" style="height:35px; width:100px;" ></td>
         </tr>
       </table>
     </form>

控制台里只能打印出来controller方法里的1和2, if (multipartResolver.isMultipart(request))这条语句往后的代码没有得到执行,这是为什么呢?很急,有没有大神帮帮忙

1个回答

method = RequestMethod.GET,上传文件能用GET这个动作? 得用POST吧

u013234356
不常发疯的疯子 可能是浏览器的问题,以前post报错,现在用IE可以了!太感谢你了!
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问