Reputation: 799
When I upload file with another details using form sumbmition, it shows an error HTTP Status 400 - type Status report message description The request sent by the client was syntactically incorrect.
jsp page
<form:form method="POST" action="addbanners?${_csrf.parameterName}=${_csrf.token}" modelAttribute="banner" enctype="multipart/form-data">
<h2>New Banner</h2>
<table>
<tr><td>Banner Name</td>
<td><form:input type="text" name="thematicdayid" id="thematicdayid" path="bannerName" /></td></tr>
<tr><td>Banner Image</td>
<td><form:input name="uploadBanner" type="file" id="uploadBanner" path="bannerImage"/></td></tr>
<tr><td> <button type="submit" class="btn btn-success" id="btnAddBanner">Add</button></td></tr>
</table>
</form:form>
filecontroller.java
@RequestMapping(value = "/addbanners", method = RequestMethod.POST)
public ModelAndView addbanners(@ModelAttribute Banner banner,@RequestParam("file") MultipartFile file){
System.out.println("File"+file);
ImageUpload imageUpload=new ImageUpload();
if(!file.isEmpty())
{
String path=context.getRealPath("");
String imagename=imageUpload.uploadImage(file,path);
banner.setBannerImage(imagename);
filewriterServices.saveBannerDetails(banner);
}
ModelAndView model = new ModelAndView();
model.setViewName("filepage");
return model;
}
I add below details in root-context.xml
<beans:bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="maxUploadSize" value="100000" />
</beans:bean>
Upvotes: 0
Views: 1696
Reputation: 799
I got the answer by changing
public ModelAndView addbanners(@ModelAttribute Banner banner,@RequestParam("file") MultipartFile file) to
public ModelAndView addbanners(@ModelAttribute Banner banner,@RequestParam("uploadBanner") MultipartFile file)
and change
<form:input name="uploadBanner" type="file" id="uploadBanner" path="bannerImage"/> to
<input name="uploadBanner" type="file" id="uploadBanner" path="bannerImage"/>
and thank you @Akash Rajbanshi to help me to find my mistake.
Upvotes: 0
Reputation: 1593
Change
public ModelAndView addbanners(@ModelAttribute Banner banner,@RequestParam("file") MultipartFile file)
to
public ModelAndView addbanners(@ModelAttribute Banner banner,@RequestParam("uploadBanner") MultipartFile file)
Upvotes: 2