spring-mvc.xml配置java
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding"> <value>UTF-8</value> </property> <property name="maxUploadSize"> <value>10485760000</value> <!-- 上傳文件大小限制爲31M,31*1024*1024 --> </property> <property name="maxInMemorySize"> <value>40960</value> </property> </bean>
jspweb
<form id="batchForm" class=" BatchInsert" action="${ctx}/StdManage/standardsBatchInsert" method="post" enctype="multipart/form-data"> <input type="file" name="filename" id="batchFile"> </form>
controllerspring
@RequestMapping("/standardsBatchInsert") @ResponseBody public Map<String, Object> standardsBatchInsert(@RequestParam("filename") MultipartFile file) { String path = "";//保存文件的地址 FileOutputStream fileOS = new FileOutputStream(path + multipartFile.getOriginalFilename()); fileOS.write(multipartFile.getBytes()); fileOS.close(); Map<String, Object> map = new HashMap<>(); map.put("success", true); map.put("msg", "上傳成功"); return map; }