I just don't get it to work, cant see why!
Invalid property 'file' of bean class [se.ud.udp.model.resource.UploadItem]: Could not instantiate property type [org.springframework.web.multipart.MultipartFile] to auto-grow nested property path: java.lang.InstantiationException: org.springframework.web.multipart.MultipartFile
applicationContext.xml
bean:Code:... <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="50000000"/> </bean> ...
Controller:Code:public class UploadItem { private MultipartFile file; private String name; public MultipartFile getFile() { return file; } public void setFile(MultipartFile file) { this.file = file; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
formCode:@Controller @RequestMapping(value = "/upload/*") @SessionAttributes("uploadItem") public class UploadController { private static final Logger log = Logger.getLogger(UploadController.class); @RequestMapping(value = "create" ,method = RequestMethod.GET) public String getUploadForm(Model model) { model.addAttribute("uploadItem", new UploadItem()); return "upload/uploadForm"; } @RequestMapping(value = "submit" , method = RequestMethod.POST) public String create(@ModelAttribute(value = "uploadItem") UploadItem uploadItem, BindingResult result,Model model) { return "upload/finished"; } }
can anyone see why?HTML Code:<html> ****<head> ********<META http-equiv="Content-Type" content="text/html;charset=UTF-8"> ********<title>Upload Example</title> ****</head> ****<body><!-- commandName="sPosition" --> PELLE: ${uploadItem.name} <form:form commandName="uploadItem" enctype="multipart/form-data" action="/upload/submit" method="post"> <form:label path="file">File:</form:label> <input type="file" name="file" /> <form:errors path="file" /> <br class="clear-both"/> <input type="submit" class="submit" value="Upload"/> ********</form:form> ****</body> </html>


Reply With Quote
