表單提交後出現400提示
HTTP Status 400 – Bad Request
Type Status Report
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
原因分析:
在前端表單提交後如果有字段爲空則在後臺接收不到值並會報錯,請求不到參數便查詢不到http頭的信息
解決方法:
1、可以在前端用js設置監聽,如果字段值爲空則設定一個默認值在執行提交操作。
<input type="text" id="myid" name="myname" />
if($("#myid").val()=="" || $("#myid").val()=null){
$("#myid").val("anyValue");
}
2、在SSM框架中也可以設定接收字段的默認值。
@RequestParam(value = "myname", defaultValue = "1") String myname