我正在开发 Spring MVC 应用程序。我遇到一种情况,我正在从弹出窗口提交信息。如何在 Controller 中编写重定向,以便我从提交弹出窗口的位置重定向到父页面。
从弹出窗口中我将转到下面的 Controller 。从那里我想进入父窗口。我不知道如何才能实现这一目标。 例如:
@Controller
@RequestMapping(Value="/home", method = {RequestMethod.POST})
public ModelAndView homepAge(@ModelAttribute("homeForm") HomeForm homeForm, BindingResult errors,
HttpServletResponse response,HttpServletRequest requst) {
...
return mnv; //here i want to go to the same page from where i came from
}
提前致谢。
最佳答案
如果您只想重定向到引用 URL,请尝试这样的操作...
@RequestMapping(value="/home", method = {RequestMethod.POST})
public ModelAndView homepAge(@ModelAttribute("homeForm") HomeForm homeForm, BindingResult errors,
HttpServletResponse response, HttpServletRequest request) throws IOException {
String referer = request.getHeader("referer");
return new ModelAndView("redirect:" + referer, model);
}
关于java - Spring MVC Controller 中重定向到父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42932513/