简体   繁体   中英

spring http error 400 The request sent by the client was syntactically incorrect

How to resolve spring 400 error.

My controller:

@InitBinder
protected void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(
            dateFormat, false));
}

@RequestMapping(value = "/admin/users/edit", method = RequestMethod.POST)
public ModelAndView editUser(final @ModelAttribute AdminForm form,
                             Principal principal) 

public class AdminForm {
    ...
    User newUser;
    public User getNewUser() { return newUser; }
    public void setNewUser(User newUser) { this.newUser = newUser; }
    ...
}

public class User {
...
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    Date birthDate;
...
}

JSP file has this input box:

  <form:input
   class="tcal"
   name="date"
   itemLabel="date"
   path="newUser.birthDate"/>

Browser generates this POST request:

newUser.fio=%D0%9F%D0%B5%D1%82%D1%80%D0%BE%D0%B2+%D0%A1%D0%B8%D0%B4%D0%BE%D1%80+%D0%9F%D0%BE%D0%BB%D0%B8%D0%BA%D0%B0%D1%80%D0%BF%D0%BE%D0%B2%D0%B8%D1%87&newUser.login=das&newUser.password=8904&newUser.birthDate=08%2F04%2F2014&newUser.id=23

You can see that there are also other fields fio, login, password and id. If I remove birthDate, then 400 error goes away, but I need this parameter.

How can I avoid this problem?

Thanx

My problem was that in one place there was java.sql.Date and java.util.Date in another. When I changed both to java.util.Date, it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM