【发布时间】:2012-03-07 21:21:42
【问题描述】:
我希望我的 Spring MVC 应用程序重定向到一个动态 URL(由用户提交)。所以如果我有这样的代码,
@RequestMapping("/redirectToSite")
protected ModelAndView redirect(
@RequestParam("redir_url") String redirectUrl,
HttpServletRequest request,
HttpServletResponse response)
{
// redirect to redirectUrl here
return ?
}
我应该写什么来重定向到提交的 URL?例如 http://mySpringMvcApp/redirectToSite?redir_url=http://www.google.com 应该重定向到 Google。
【问题讨论】:
-
你试过 new ModelAndView(new RedirectView(redirectUrl)) 吗?
-
@Joe:同样有效。很棒的东西。
-
不确定您是否考虑过这一点,但您应该考虑到开放式重定向是一种安全反模式,并且您至少应该在实际重定向到之前对提交的 url 进行基本验证。参见例如owasp.org/index.php/…
标签: spring redirect spring-mvc