SSM搭項目報錯: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).

在用表單提交數據的時候,出現如上所示的錯誤。根據描述可以看出事客戶端數據提交時發生的錯誤,可能是請求的語法或者路徑錯誤。

最后發現,表單提交的時候,日期類型是按照字符串提交的,而服務器用的Date類型來接,所以會出錯,在控制器里添加代碼:

 @InitBinder public void init(WebDataBinder webDataBinder){ //指定什么格式,前台傳什么格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); simpleDateFormat.setLenient(false); webDataBinder.registerCustomEditor(Date.class,new CustomDateEditor(simpleDateFormat,false)); }
 @InitBinder public void init(WebDataBinder webDataBinder){ //指定什么格式,前台傳什么格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); simpleDateFormat.setLenient(false); webDataBinder.registerCustomEditor(Date.class,new CustomDateEditor(simpleDateFormat,false)); }

由此便可解決問題。

如果提交的表單時,如果某些數據沒有填,而后台做出了“接收”的行為,也會報如上錯誤。

 


免責聲明!

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



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