这是我的形式:请求方法“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