Spring HTTP Status 400 - The request sent by the client was syntactically incorrect (when adding date input)

∥☆過路亽.° 提交于 2019-12-01 01:55:54

There are two probems:

  • 1 the parameters (idTaskCategory, idTaskPriority, idXXX) does not match the Task fields. (this is not the cause for your problem, but it will just not work. And when you change the names so that they match, it problem is that your request contains ids, but your Task expect objects. So you need to make the task expect ids too, or you need to register some converter)

  • 2 (I think that this is the problem), I expect that the date format / converter does not accept the submitted date format. Add @DateTimeFormat(pattern = "yyyy-MM-dd") to all date fields.

I think one problem could be that you use the http method GET. A GET Request send the parameter by using the URL query string (the stuff after the ?). But the total length of the URL is technical restricted by browsers, chaches, webservers. So one cause for the problem could be, that the URL gets to long, if you have a lot of paramters or a "long" value (for example a long description). (this is correct, but not the cause)

So I would recommend to use http method POST instead. -- And using POST is the better verb for an Request that changes something on the server (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html) .

Prakash Gaikwad

A long time back I also faced this problem.

I solved it using:

@InitBinder

protected void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(
            dateFormat, false));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!