其实跟Struts上传文件差不多。都需要用到Apache的common-fileUpload和common-io的jar包。下面说个大概吧,首先在springmvc的配置文件中需要配置你上传的需要借助的东西(下面两个配置选一个就可以了):①、使用common的fileUpload
id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
@RequestMapping(value = "/form", method = RequestMethod.POST)
public String handleFormUpload(@RequestParam("name")
String name,@RequestParam("file") MultipartFile file) {
if(!file.isEmpty()) {
byte[] bytes = file.getBytes();
// 这里就把获得的byte字节文件数据做操作
return "uploadSuccess";//上传成功
}
return "uploadFailure"; //上传失败
}