Spring MVC HTTP Status 400 - Bad Request

前端 未结 2 1946
情书的邮戳
情书的邮戳 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.

    0 讨论(0)
  • 2021-01-20 18:44

    According to your code you are using

    <prop key="index.htm">indexController</prop>
    <a href="register.htm">click</a>
    

    in above code spelling is not correct (htm instead of HTML).

    <prop key="index.html">indexController</prop>
    <a href="register.html">click</a>
    
    0 讨论(0)
提交回复
热议问题