Spring 表单提交400必需的字符串参数不存在
我试图将表单中的数据简单地发布到我的spring控制器,我总是收到错误消息: 服务器响应状态为400必需字符串参数 “profileId”不存在 我的uiBinder中的表格:Spring 表单提交400必需的字符串参数不存在,spring,forms,post,gwt,Spring,Forms,Post,Gwt,我试图将表单中的数据简单地发布到我的spring控制器,我总是收到错误消息: 服务器响应状态为400必需字符串参数 “profileId”不存在 我的uiBinder中的表格: <g:FormPanel ui:field="formPanel"> <g:HTMLPanel> <table border="0" width="100%"> <tr>
<g:FormPanel ui:field="formPanel">
<g:HTMLPanel>
<table border="0" width="100%">
<tr>
<td width="20%"><g:HTML HTML="Profile ID:" /></td>
<td width="80%"><g:TextBox name="profileId" ui:field="profileId" width="300px" "/>
<td width="20%"><g:HTML HTML="Logo: " /></td>
<td width="80%"> <g:FileUpload name="logo" ui:field="logoUpload"/> </td>
</tr>
</table><br/>
</g:HTMLPanel>
</g:FormPanel>
我的spring控制器:
@RequestMapping(method = RequestMethod.POST, value = "/create")
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public void create(@RequestParam("profileId") String profileId,
@RequestParam("logo") MultipartFile logo) throws BadRequestException, InternalException, NotFoundException{
log.info("Request to create new user.");
}
使用chrome开发工具跟踪的请求有效负载:
---WebKitFormBoundaryX7km8vQwaC3LtjqO内容配置:表单数据;name=profileId
测试1
---WebKitFormBoundaryX7km8vQwaC3LtjqO内容配置:表单数据;名称=徽标;filename=test1.png内容类型:image/png
---WebKitFormBoundaryX7km8vQwaC3LtjqO-
Eclipse控制台输出:
[WARN] 400 - POST /create (127.0.0.1) 1495 bytes Request headers
Host: lokalhorst.com:55409
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
Referer: http://lokalhorst.com:55409/admin.html
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: JSESSIONID=63vn7rbgnrqa
Content-Length: 10244
Pragma: no-cache
Cache-Control: no-cache
Origin: lokalhorst.com:55409
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryX7km8vQwaC3LtjqO Response headers
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1495
谢谢你的帮助
我需要将MulitpartResolver添加到servlet或applicationcontext中
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="250000"/>
</bean>
已在问题中讨论过可能的副本
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="250000"/>
</bean>