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


前幾天遇到過這個問題(Ref:http://www.cnblogs.com/xiandedanteng/p/4168609.html),問題在頁面的組件name和和注解的@param名匹配不對,這個好解決,一一對好就行了。

但是,這回情況不一樣了,我的頁面控件是類似這樣的:

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

而控制器是這樣寫的:

@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){
。。。
}

看,to部分對應一點沒錯,但是,問題來了,如果name為to的一組復選框一個都沒有選中的話,那么,提交頁面后就會報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>

這樣,這組復選框就不必非要選中一個了,當然,后台需要添加點過濾措施。

應該是SpringMVC自身的問題,希望它能修正這個Bug。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM