這是我的形式:請求方法「POST」春不支持MVC
<form action="${pageContext.request.contextPath}/admin/editc" method="POST" id="editForm">
<input type="text" name="username" class="form-control" />
<input type="text" name="password" class="form-control" />
<input type="submit" value="submit" >
</form>
這是我的控制器方法:
@RequestMapping(value = "/admin/edit", method = RequestMethod.GET)
public ModelAndView editPage() {
ModelAndView model = new ModelAndView();
model.addObject("title", "User edit Form - Database Interaction");
model.addObject("message", "This page is for ROLE_ADMIN only!");
model.setViewName("editpage");
System.out.println("getting edit page");
return model;
}
@RequestMapping(value = "/admin/editc", method = RequestMethod.POST)
public ModelAndView updateCredentials() {
// System.out.println("Username= "+username+" password= "+password);
ModelAndView model = new ModelAndView();
model.addObject("title", "Credential Edit Operation");
model.addObject("message", "You are successfully updated your credentials");
model.addObject("edited", "TRUE");
model.setViewName("editpage");
System.out.println("executed updateCredentials POST method");
return model;
}
現在的問題是我收到405錯誤控制檯類似如下:
org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
WARNING: Request method 'POST' not supported
任何人都可以幫我解決這個錯誤嗎?
我在發佈的代碼中看不到任何錯誤。其他事情出錯了。它很難說出它可能出錯的地方。要進一步調試,您的電話工作正常嗎?如果是這樣,當服務器啓動時,它會吐出請求映射的細節。檢查映射是否綁定到控制器。 – minion 2015-03-25 18:49:54