The request sent by the client was syntactically incorrect.-Spring MVC + JDBC Template

前端 未结 6 1681
攒了一身酷
攒了一身酷 2020-11-29 05:52

I am newbie to Spring MVC. I was stuck by an error while running my project Error-The request sent by the client was syntactically incorrect. I have an enti

6条回答
  •  青春惊慌失措
    2020-11-29 06:48

    I think the issue is that Spring doesn't know how to deserialize the date your browser client sends when submitting the following input field in

    
        Date Of Birth
        
            Click Here to Pick up the timestamp
        
    
    

    Spring doesn't know how to take the value that you enter into that field and convert it into a Date object. You need to register a PropertyEditor for that. For example, add the following to your @Controller class

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

    Obviously, change the SimpleDateFormat to whatever your client is sending.


    On a related note, you're sending a 302 response by sending a redirect

    return "redirect:/full-reg";
    

    Remember that request and model attributes only live for the duration of one request. So when your client send the request to full-reg, none of the form input parameters you sent originally exist any more. You should re-think how you do this.

提交回复
热议问题