表单提交400必需的字符串参数不存在

时间:2014-11-21 11:57:52

标签: spring forms post gwt

我尝试将简单的POST数据从我的表单发送到我的spring控制器,并且总是收到错误消息:

  

服务器响应状态为400(必需字符串参数   '简档'不存在)

我的uiBinder中的表格:

<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>

视图中的提交:

String actionUrl = com.google.gwt.core.client.GWT.getHostPageBaseURL() + "/create";
formPanel.setAction(actionUrl);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.submit();

我的春季控制员:

@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 dev工具跟踪请求有效负载:

  

------ WebKitFormBoundaryX7km8vQwaC3LtjqO Content-Disposition:form-data;名称=&#34;简档&#34;

     

TEST1   ------ WebKitFormBoundaryX7km8vQwaC3LtjqO Content-Disposition:form-data;命名=&#34;标志&#34 ;;文件名=&#34; test1.png&#34;内容类型: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

感谢您的帮助。

no duplication; also not helping

1 个答案:

答案 0 :(得分:0)

我需要将MulitpartResolver添加到我的servlet(或applicationcontext)

<bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="250000"/>
</bean> 

已在问题MultipartForm handling with Spring

中讨论过