【发布时间】:2013-10-09 10:55:50
【问题描述】:
我正在开发一个 Spring MVC 项目,我正在尝试提交一个表单并在同一个 jsp 页面中处理它,以便对用户进行身份验证。
我确实通过使用 ajax 请求调用内置于 Controller 中的 Web 服务对用户进行了身份验证,但为了在这次不使用 Ajax 的情况下做到这一点,我收到了这个错误 Request method 'POST' not supported
这是我的代码:
表格
<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");
}
【问题讨论】:
标签: java spring jsp spring-mvc