[英]Handling form submission in a jsp page in Spring MVC
I am working on a Spring MVC project, an I'm trying to submit a form and handle it in the same jsp page in order to authenticate the user. 我正在一个Spring MVC项目上,我正在尝试提交一个表单并在同一jsp页面中处理它以便认证用户。
I did authonticate the user by calling a web service built in a Controller with an ajax request , but in order to do that without using Ajax this time I got this error Request method 'POST' not supported
我确实通过使用ajax请求调用Controller中内置的Web服务对用户进行了身份验证,但是为了这次不使用Ajax这样做,我得到了此错误Request method 'POST' not supported
Here is my code: 这是我的代码:
The form 表格
<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 code 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");
}
您必须像这样映射控制器:
@RequestMapping(value="/", method = RequestMethod.POST)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.