【发布时间】:2016-11-11 08:07:51
【问题描述】:
试图从控制器方法重定向到另一个控制器,遇到以下错误
org.springframework.web.HttpRequestMethodNotSupportedException:不支持请求方法“GET”
我在控制器 1 中有 submitForm 方法,一旦我调用提交方法,它应该调用控制器 2
控制器 1
@RequestMapping(method = RequestMethod.POST)
public ModelAndView submitForm(@ModelAttribute("loginForm") Login login, BindingResult errors, SessionStatus status, HttpServletRequest request, HttpServletResponse response) throws IOException {
return new ModelAndView("path2.sp");
}
控制器 2
@Controller
@RequestMapping("path2.sp")
public class DestinationController {
System.out.println("");
}
【问题讨论】:
-
你想调用 GET 方法但在你的控制器中你只有 post
-
DestinationController甚至没有从submitForm方法接收重定向调用的方法。在DestinationController中创建一个可以接收请求调用的方法。 -
我想接收班级级别的请求
-
DestinationController 没有任何动作方法?
-
action 方法依赖于其他方法,如 showForm、initBinder、参考数据等。
标签: spring spring-mvc model-view-controller