I am trying to add image loading to my freemarker page (ftl file) using spring and hibernate technology - this is the error I had every time I started the application:
HTTP Status 500 - The server encountered an internal error () that prevented it from completing this request.
and this is the code:
1-POM file:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
2-app-config.xml:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
3-ftl file:
<input type="file" id="image" name="image" value="">
4-web controller:
@RequestMapping(method= RequestMethod.POST)
public String post(Model model , HttpServletRequest req , HttpSession session,@RequestParam("image") MultipartFile multipartFile) throws IOException{
multipartFile.getBytes();
File destination = new File("/home/user/Pictures/" + multipartFile.getOriginalFilename());
multipartFile.transferTo(destination);
destination.delete();
return "redirect:index";
}
se7so source
share