The current request is not a multipart request
2016-07-10 00:00
549 查看
摘要: The current request is not a multipart request
配置上传组件:
1、添加commons-io,commons-fileupload 两个jar包
2、applicaitonContext.xml配置文件中配置上传组件bean
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8" />
<property name="maxUploadSize" value="10485760000" />
</bean>
3、上传表单添加enctype属性 enctype="multipart/form-data" 注意 注意 注意 如果直接粘贴此内容过去,请注意张贴后标点符号是否是英文状态(老子因为这个原因,搞了两天)
4、controller中接收:用MultipartFile file 做为接收参数,传入对应的方法即可
@RequestMapping("test/upload.do")
public String upload(@RequestParam(value="file",required=true) MultipartFile file){
try {
System.out.println("originalName:"+file.getOriginalFilename());
System.out.println("inputStream:"+file.getInputStream());
String fileName = file.getOriginalFilename();
File newFile = new File("d:/file",fileName);
file.transferTo(newFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "index/auhtorCenter";
}
配置上传组件:
1、添加commons-io,commons-fileupload 两个jar包
2、applicaitonContext.xml配置文件中配置上传组件bean
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8" />
<property name="maxUploadSize" value="10485760000" />
</bean>
3、上传表单添加enctype属性 enctype="multipart/form-data" 注意 注意 注意 如果直接粘贴此内容过去,请注意张贴后标点符号是否是英文状态(老子因为这个原因,搞了两天)
4、controller中接收:用MultipartFile file 做为接收参数,传入对应的方法即可
@RequestMapping("test/upload.do")
public String upload(@RequestParam(value="file",required=true) MultipartFile file){
try {
System.out.println("originalName:"+file.getOriginalFilename());
System.out.println("inputStream:"+file.getInputStream());
String fileName = file.getOriginalFilename();
File newFile = new File("d:/file",fileName);
file.transferTo(newFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "index/auhtorCenter";
}
相关文章推荐
- Pull is not possible because you have unmerged ...
- Ubuntu 下修改 Could not reliably determine the serve
- Linux下提示命令找不到:bash:command not found
- CISCO交换机概览
- 攻击CISCO路由器
- IIS漏洞整理大全
- IIS配置文件隐患
- 解决Default storage engine (InnoDB) is not available导致mysql无法启动的修改办法
- MySQL4 File ‘c:\mysql\share\charsets\?.conf’ not found (Errcode: 22)的解决方法
- C#中is和as用法实例分析
- C#中的is和as操作符区别小结
- php错误提示failed to open stream: HTTP request failed!的完美解决方法
- PHP通过session id 实现session共享和登录验证的代码
- C#中is与as的区别分析
- 小论asp中request与response的用法
- IIS访问ASP页面时报错The requested resource is in use.的解决办法
- 循环取值Request.QueryString的用法
- HttpServletRequest对象
- 如何处理日志文件丢失