1. 程式人生 > >jsp 跳轉controller頁面 報400

jsp 跳轉controller頁面 報400

跳轉報400,很有可能是jsp頁面傳遞的引數和controller接收的引數型別不一致,這裡的引數一致是指 和實體類中保持一致。

當jsp頁面中出現date欄位時,在controller中需要實現Converter介面進行處理,否則會報400異常。

在controller中如下:

@InitBinder
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)throws Exception {
DateFormat fmt=new SimpleDateFormat("yyyy-MM-dd");
CustomDateEditor dateEditor=new CustomDateEditor(fmt, true);
binder.registerCustomEditor(Date.class, dateEditor);
}