HTTP Status 400 – Bad Request Type Status Report 服务器由于被认为是客户端错误

表单提交后出现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设置监听,如果字段值为空则设定一个默认值在执行提交操作。

if($("#myid").val()=="" || $("#myid").val()=null){
    $("#myid").val("anyValue");
}
     

2、在SSM框架中也可以设定接收字段的默认值。

@RequestParam(value = "myname", defaultValue = "1") String myname

 

你可能感兴趣的:(java)