2016-11-11 366 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

你可以發佈你的堆棧跟蹤嗎? –

相關問題