2016-11-11 360 views
0

试图从控制器方法重定向到另一个控制器,面向下面误差请求方法“GET”不支持

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(""); 
} 
+0

你要调用get方法,但在你的控制器,你有只发布 –

+0

'DestinationController'甚至没有从'submitForm'方法接收重定向调用的方法。在'DestinationController'中创建一个可以接收请求调用的方法。 –

+0

我想收到课堂级别的请求 – Anamika

回答

0

这不是做重定向的方式。

首先,解决您的@RequestMapping在控制器2,像这样:现在

@Controller 
@RequestMapping("/path2") 
public class DestinationController { 
    System.out.println(""); 
} 

,在控制器1只是这样做:

@RequestMapping(method = RequestMethod.POST) 
public String submitForm(@ModelAttribute("loginForm") Login login, BindingResult errors, SessionStatus status, HttpServletRequest request, HttpServletResponse response) throws IOException { 
    return "redirect:/path2"; 
} 
+0

我做了仍然面临同样问题的变化 – Anamika

+0

你可以发布你的堆栈跟踪吗? –

相关问题