From 19e944bd4f0487bff173c3abcdbd9c7529bbd88c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 18 Jul 2018 14:43:14 +0200 Subject: [PATCH] UrlBasedViewResolver exposes redirect prefix as bean name Issue: SPR-17045 --- .../servlet/view/UrlBasedViewResolver.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java index ef7cd69e266..02ccd579f7b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java @@ -50,12 +50,12 @@ import org.springframework.web.servlet.View; * "/WEB-INF/jsp/test.jsp" * *

As a special feature, redirect URLs can be specified via the "redirect:" - * prefix. E.g.: "redirect:myAction.do" will trigger a redirect to the given + * prefix. E.g.: "redirect:myAction" will trigger a redirect to the given * URL, rather than resolution as standard view name. This is typically used * for redirecting to a controller URL after finishing a form workflow. * - *

Furthermore, forward URLs can be specified via the "forward:" prefix. E.g.: - * "forward:myAction.do" will trigger a forward to the given URL, rather than + *

Furthermore, forward URLs can be specified via the "forward:" prefix. + * E.g.: "forward:myAction" will trigger a forward to the given URL, rather than * resolution as standard view name. This is typically used for controller URLs; * it is not supposed to be used for JSP URLs - use logical view names there. * @@ -214,7 +214,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements * interpreted as relative to the web application root, i.e. the context * path will be prepended to the URL. *

Redirect URLs can be specified via the "redirect:" prefix. - * E.g.: "redirect:myAction.do" + * E.g.: "redirect:myAction" * @see RedirectView#setContextRelative * @see #REDIRECT_URL_PREFIX */ @@ -241,7 +241,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements * difference. However, some clients depend on 303 when redirecting * after a POST request; turn this flag off in such a scenario. *

Redirect URLs can be specified via the "redirect:" prefix. - * E.g.: "redirect:myAction.do" + * E.g.: "redirect:myAction" * @see RedirectView#setHttp10Compatible * @see #REDIRECT_URL_PREFIX */ @@ -342,7 +342,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements *

  • {@code true} - all Views resolved by this resolver will expose path variables *
  • {@code false} - no Views resolved by this resolver will expose path variables *
  • {@code null} - individual Views can decide for themselves (this is used by the default) - * * @see AbstractView#setExposePathVariables */ public void setExposePathVariables(Boolean exposePathVariables) { @@ -453,18 +453,22 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements if (!canHandle(viewName, locale)) { return null; } + // Check for special "redirect:" prefix. if (viewName.startsWith(REDIRECT_URL_PREFIX)) { String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length()); - RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible()); + RedirectView view = new RedirectView(redirectUrl, + isRedirectContextRelative(), isRedirectHttp10Compatible()); view.setHosts(getRedirectHosts()); - return applyLifecycleMethods(viewName, view); + return applyLifecycleMethods(REDIRECT_URL_PREFIX, view); } + // Check for special "forward:" prefix. if (viewName.startsWith(FORWARD_URL_PREFIX)) { String forwardUrl = viewName.substring(FORWARD_URL_PREFIX.length()); return new InternalResourceView(forwardUrl); } + // Else fall back to superclass implementation: calling loadView. return super.createView(viewName, locale); } @@ -486,7 +490,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements /** * Delegates to {@code buildView} for creating a new instance of the - * specified view class, and applies the following Spring lifecycle methods + * specified view class. Applies the following Spring lifecycle methods * (as supported by the generic Spring bean factory): *