0
我有一些方法如何從控制器重定向到另一個控制器到POST方法?
@RequestMapping(value = "process", method = RequestMethod.POST)
public ModelAndView process(HttpServletRequest request) {
ModelAndView modelAndView;
String phoneNumber = request.getParameter("phone_number");
int amount = Integer.parseInt(request.getParameter("amount"));
String result = validateService.validate(phoneNumber, amount);
if (!result.equals("OK")) {
modelAndView = new ModelAndView("start");
modelAndView.addObject("result",result);
}else {
modelAndView = new ModelAndView("redirect:/check/process");
modelAndView.addObject("phone_number",phoneNumber);
modelAndView.addObject("amount",amount);
}
return modelAndView;
}
我需要重定向到另一個控制器POST方法。但我有一個錯誤
HTTP Status 405 - Request method 'GET' not supported
它IST第二控制器
@Controller
@RequestMapping("/check")
public class CheckController {
@RequestMapping(value = "process", method = RequestMethod.POST)
public ModelAndView process(HttpServletRequest request) {
ModelAndView modelAndView = new ModelAndView("check");
String phoneNumber = request.getParameter("phone_number");
int amount = Integer.parseInt(request.getParameter("amount"));
return modelAndView;
}
}
當我試圖重定向
tl; dr你不能,如果你需要這個,你只是不太明白http是如何工作的,你可以解釋你的用例,然後我們可以幫你找出一個有效的解決方案 – Jaiwo99
我怎麼能叫新控制器從我的方法? – user5620472
的問題是爲什麼? – Jaiwo99