我正在开发一个 Spring MVC 项目,我正在尝试提交表单并在同一jsp 页面中处理它,以便对用户进行身份验证。
我确实通过使用 ajax 请求调用 Controller 中内置的 Web 服务对用户进行了身份验证,但为了这次不使用 Ajax 来做到这一点,我收到了此错误 Request method '不支持 POST
这是我的代码:
表格
<form action="/gethealthy/isuser" method="post">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<button type="submit">Sign In</button>
</form>
JSP代码
if (request.getParameter("username") != null) {
HomeController aHomeController = new HomeController();
String username = request.getParameter("username");
String password = request.getParameter("password");
String result = aHomeController.isUser(username, password);
if (aHomeController.isUser(username, password)) {
String redirectURL = "project/dashboard";
response.sendRedirect(redirectURL);
} else {
out.print("Wrong credentials");
}
最佳答案
你必须像这样映射你的 Controller :
@RequestMapping(value="/", method = RequestMethod.POST)
关于java - 在 Spring MVC 中处理 jsp 页面中的表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270095/