Spring MVC HTTP Status 400 - Bad Request

前端 未结 2 1947
情书的邮戳
情书的邮戳 2021-01-20 17:43

I am trying to run a project in Spring MVC. Here is the code

index.jsp

<%@page contentType=\"text/html\" pageEncoding=\"UTF-8\"%>
<%@taglib          


        
2条回答
  •  情歌与酒
    2021-01-20 18:39

    You must bind the Date when you submit a HTTP POST. Spring does not know that this is a Date, it sees it as a String.

    Add this:

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        sdf.setLenient(true);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }
    

    To your controller.

提交回复
热议问题