且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

又见The request sent by the client was syntactically incorrect ()

更新时间:2022-09-11 19:34:15

前几天遇到过这个问题(Ref:http://www.cnblogs.com/xiandedanteng/p/4168609.html),问题在页面的组件name和和注解的@param名匹配不对,这个好解决,一一对好就行了。

但是,这回情况不一样了,我的页面控件是类似这样的:

又见The request sent by the client was syntactically incorrect ()
<p style="height:280px;display:block;">
    <span class="req">
        <label><input type="checkbox" value="A" name="to" />&nbsp;A</label>
        <label><input type="checkbox" value="B" name="to" />&nbsp;B</label>
        <label><input type="checkbox" value="C" name="to" />&nbsp;C</label>
    </span>
    <label><span></span></label>
</p>
又见The request sent by the client was syntactically incorrect ()

而控制器是这样写的:

又见The request sent by the client was syntactically incorrect ()
@RequestMapping(value="/sendEmailReport")
    public String sendEmailReport(@RequestParam("idTxt") String id,
                                  @RequestParam("to")  String[] to,
                                  @RequestParam("cc")  String[] cc,
                                  @RequestParam("bcc") String[] bcc,
                                  HttpServletRequest request,
                                  HttpServletResponse response){
。。。
}
又见The request sent by the client was syntactically incorrect ()

看,to部分对应一点没错,但是,问题来了,如果name为to的一组复选框一个都没有选中的话,那么,提交页面后就会报The request sent by the client was syntactically incorrect ()错误。

但是,如果哪怕只要选中一个,程序就正常运行了。

我是通过添加一个默认的隐藏的选中复选框来避免这个错误的,代码如下:

又见The request sent by the client was syntactically incorrect ()
<p style="height:280px;display:block;">
    <span class="req">
        <label><input type="checkbox" value="A" name="to" />&nbsp;A</label>
        <label><input type="checkbox" value="B" name="to" />&nbsp;B</label>
        <label><input type="checkbox" value="C" name="to" />&nbsp;C</label>
        <label><input type="checkbox" value="" checked name="to" style="display:none;"/></label>
    </span>
    <label><span></span></label>
</p>
又见The request sent by the client was syntactically incorrect ()

这样,这组复选框就不必非要选中一个了,当然,后台需要添加点过滤措施。

应该是SpringMVC自身的问题,希望它能修正这个Bug。

 










本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/xiandedanteng/p/4189489.html,如需转载请自行联系原作者