我想从带有post参数的spring控制器重定向到另一个页面(在我的应用程序之外)。我搜索了很多,但没有任何解决方案。
答案 0 :(得分:4)
您将无法添加POST,但您可以使用GET重定向。执行以下操作:
@RequestMapping("/redirectMe")
public void redirectMe (HttpServletResponse response){
response.sendRedirect("http://redirected.com/form?someGetParam=foo");
}
答案 1 :(得分:1)
做这样的事情
@RequestMapping(value="/someUrl",method=RequestMethod.POST)
public String myFunc(HttpServletRequest request,HttpServletResponse response,Map model){
//do sume stuffs
return "redirect:/anotherUrl"; //gets redirected to the url '/anotherUrl'
}
@RequestMapping(value="/anotherUrl",method=RequestMethod.GET)
public String myAnotherFunc(HttpServletRequest request,HttpServletResponse response){
//do sume stuffs
return "someView";
}
答案 2 :(得分:0)
简便的方法:
@PostMapping("/redirectPostToPost")
public ModelAndView redirectPostToPost(HttpServletRequest request) {
request.setAttribute(
View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.TEMPORARY_REDIRECT);
return new ModelAndView("redirect:/redirectedPostToPost");
}
@PostMapping("/redirectedPostToPost")
public ModelAndView redirectedPostToPost() {
return new ModelAndView("redirection");
}