我正在尝试使用apache common-fileupload和spring上传文件,我的表单也包含字段。但是当我试图提交总是得到空指针异常时
现在使用Multipartstream获取相同的解决方案。
@RequestMapping(value="/uploadfile.do", method = RequestMethod.POST)
public ModelAndView uploadFile(@ModelAttribute("frm") ReceiptForm form, BindingResult result, HttpServletRequest request){
System.out.println("---"+form.getProductName());
System.out.println("---"+form.getRfile());
ModelAndView mav = new ModelAndView("receipt/upload");
mav.addObject("command", form);
return mav;
}
答案 0 :(得分:1)
以下示例显示如何使用CommonsMultipartResolver:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="100000"/>
通过将此添加到您的spring配置,您的控制器应该拾取文件上传