![](/img/trans.png)
[英]HTTP Status 400 The request sent by the client was syntactically incorrect in Spring
[英]spring http error 400 The request sent by the client was syntactically incorrect
如何解決spring 400錯誤。
我的控制器:
@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文件具有以下輸入框:
<form:input
class="tcal"
name="date"
itemLabel="date"
path="newUser.birthDate"/>
瀏覽器生成此POST請求:
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
您可以看到還有其他字段,例如:登錄名,密碼和ID。 如果我刪除了birthDate,則400錯誤消失了,但是我需要此參數。
如何避免這個問題?
感謝名單
我的問題是,在一個地方有java.sql.Date和java.util.Date。 當我將它們都更改為java.util.Date時,它起作用了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.