当我使用表单提交上传包含其他详细信息的文件时,它显示错误 HTTP 状态 400 - 类型 状态报告 信息 描述 客户端发送的请求在语法上不正确。
jsp页面
<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>
文件 Controller .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;
}
我在 root-context.xml 中添加以下详细信息
<beans:bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="maxUploadSize" value="100000" />
</beans:bean>
最佳答案
改变
public ModelAndView addbanners(@ModelAttribute Banner banner,@RequestParam("file") MultipartFile file)
至
public ModelAndView addbanners(@ModelAttribute Banner banner,@RequestParam("uploadBanner") MultipartFile file)
关于java - Spring MVC - 上传文件显示客户端发送的请求在语法上不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317902/