具體報錯如下:
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)); }
由此便可解決問題。
如果提交的表單時,如果某些數據沒有填,而后台做出了“接收”的行為,也會報如上錯誤。