[英]Handling form submission in a jsp page in Spring MVC
我正在一個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");
}
您必須像這樣映射控制器:
@RequestMapping(value="/", method = RequestMethod.POST)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.