Skip to content

Commit ae1d500

Browse files
committed
UrlBasedViewResolver exposes redirect prefix as bean name
Issue: SPR-17045 (cherry picked from commit b8d2a16)
1 parent 9134588 commit ae1d500

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
* "/WEB-INF/jsp/test.jsp"
5353
*
5454
* <p>As a special feature, redirect URLs can be specified via the "redirect:"
55-
* prefix. E.g.: "redirect:myAction.do" will trigger a redirect to the given
55+
* prefix. E.g.: "redirect:myAction" will trigger a redirect to the given
5656
* URL, rather than resolution as standard view name. This is typically used
5757
* for redirecting to a controller URL after finishing a form workflow.
5858
*
59-
* <p>Furthermore, forward URLs can be specified via the "forward:" prefix. E.g.:
60-
* "forward:myAction.do" will trigger a forward to the given URL, rather than
59+
* <p>Furthermore, forward URLs can be specified via the "forward:" prefix.
60+
* E.g.: "forward:myAction" will trigger a forward to the given URL, rather than
6161
* resolution as standard view name. This is typically used for controller URLs;
6262
* it is not supposed to be used for JSP URLs - use logical view names there.
6363
*
@@ -224,7 +224,7 @@ protected String getContentType() {
224224
* interpreted as relative to the web application root, i.e. the context
225225
* path will be prepended to the URL.
226226
* <p><b>Redirect URLs can be specified via the "redirect:" prefix.</b>
227-
* E.g.: "redirect:myAction.do"
227+
* E.g.: "redirect:myAction"
228228
* @see RedirectView#setContextRelative
229229
* @see #REDIRECT_URL_PREFIX
230230
*/
@@ -251,7 +251,7 @@ protected boolean isRedirectContextRelative() {
251251
* difference. However, some clients depend on 303 when redirecting
252252
* after a POST request; turn this flag off in such a scenario.
253253
* <p><b>Redirect URLs can be specified via the "redirect:" prefix.</b>
254-
* E.g.: "redirect:myAction.do"
254+
* E.g.: "redirect:myAction"
255255
* @see RedirectView#setHttp10Compatible
256256
* @see #REDIRECT_URL_PREFIX
257257
*/
@@ -354,7 +354,7 @@ public Map<String, Object> getAttributesMap() {
354354
* <li>{@code true} - all Views resolved by this resolver will expose path variables
355355
* <li>{@code false} - no Views resolved by this resolver will expose path variables
356356
* <li>{@code null} - individual Views can decide for themselves (this is used by the default)
357-
* <ul>
357+
* </ul>
358358
* @see AbstractView#setExposePathVariables
359359
*/
360360
public void setExposePathVariables(@Nullable Boolean exposePathVariables) {
@@ -469,21 +469,25 @@ protected View createView(String viewName, Locale locale) throws Exception {
469469
if (!canHandle(viewName, locale)) {
470470
return null;
471471
}
472+
472473
// Check for special "redirect:" prefix.
473474
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
474475
String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
475-
RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible());
476+
RedirectView view = new RedirectView(redirectUrl,
477+
isRedirectContextRelative(), isRedirectHttp10Compatible());
476478
String[] hosts = getRedirectHosts();
477479
if (hosts != null) {
478480
view.setHosts(hosts);
479481
}
480-
return applyLifecycleMethods(viewName, view);
482+
return applyLifecycleMethods(REDIRECT_URL_PREFIX, view);
481483
}
484+
482485
// Check for special "forward:" prefix.
483486
if (viewName.startsWith(FORWARD_URL_PREFIX)) {
484487
String forwardUrl = viewName.substring(FORWARD_URL_PREFIX.length());
485488
return new InternalResourceView(forwardUrl);
486489
}
490+
487491
// Else fall back to superclass implementation: calling loadView.
488492
return super.createView(viewName, locale);
489493
}
@@ -505,7 +509,7 @@ protected boolean canHandle(String viewName, Locale locale) {
505509

506510
/**
507511
* Delegates to {@code buildView} for creating a new instance of the
508-
* specified view class, and applies the following Spring lifecycle methods
512+
* specified view class. Applies the following Spring lifecycle methods
509513
* (as supported by the generic Spring bean factory):
510514
* <ul>
511515
* <li>ApplicationContextAware's {@code setApplicationContext}

0 commit comments

Comments
 (0)