我在Spring MVC Controller操作中有以下字符串。我希望控制器操作呈现一个视图页面,该视图页面接受以下字符串,然后执行重定向。
String redirectUrl = "http://www.yahoo.com"
我的控制器操作如下所示:
@RequestMapping(method = RequestMethod.GET)
public String showForm(HttpServletRequest request, ModelMap model)
{
String redirectUrl = "http://www.yahoo.com";
model.addAttribute("redirectUrl", redirectUrl);
return "loginSuccess"; //this is my view JSP file
}
在JSP视图中是否有办法在不使用JSTL的情况下进行此重定向?我想要一个干净的重定向,而不是发送任何查询字符串参数。
谢谢,
答案 0 :(得分:1)
也许我误解了但是如果你想要重定向,你将不得不使用RedirectView
。
String redirectUrl = "http://www.yahoo.com";
return "redirect:" + redirectUrl;
或使用RedirectView
实例
@RequestMapping(method = RequestMethod.GET)
public View showForm(HttpServletRequest request, ModelMap model)
{
String redirectUrl = "http://www.yahoo.com";
RedirectView view = new RedirectView(redirectUrl );
return view;
}