1. 程式人生 > >The server cannot or will not process the request due to something that is perceived to be a client

The server cannot or will not process the request due to something that is perceived to be a client

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


Apache Tomcat/9.0.12

 <form action="update" method="post">
        出生日期:<input type="date" name="time">
        <input type="submit" value="提交">
    </form>

錯誤理由很簡單,你傳的資料有問題,要麼寫的約束,要麼時間型別格式

解決方案:

    @InitBinder
    public void init(WebDataBinder binder){
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class,new CustomDateEditor(dateFormat,true));
    }

還有一種註解方法,簡單推薦。

引數pattern中寫時間格式

@DateTimeFormat(pattern = "yyyy-MM-dd")

在控制器中還要寫

@Valid

不管在bean中localdate,date都可以處理錯誤。