繁体   English   中英

春季HTTP错误400客户端发送的请求在语法上不正确

[英]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.

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