Skip to content

Commit 19e944b

Browse files
committed
UrlBasedViewResolver exposes redirect prefix as bean name
Issue: SPR-17045
1 parent e9e864b commit 19e944b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
* "/WEB-INF/jsp/test.jsp"
5151
*
5252
* <p>As a special feature, redirect URLs can be specified via the "redirect:"
53-
* prefix. E.g.: "redirect:myAction.do" will trigger a redirect to the given
53+
* prefix. E.g.: "redirect:myAction" will trigger a redirect to the given
5454
* URL, rather than resolution as standard view name. This is typically used
5555
* for redirecting to a controller URL after finishing a form workflow.
5656
*
57-
* <p>Furthermore, forward URLs can be specified via the "forward:" prefix. E.g.:
58-
* "forward:myAction.do" will trigger a forward to the given URL, rather than
57+
* <p>Furthermore, forward URLs can be specified via the "forward:" prefix.
58+
* E.g.: "forward:myAction" will trigger a forward to the given URL, rather than
5959
* resolution as standard view name. This is typically used for controller URLs;
6060
* it is not supposed to be used for JSP URLs - use logical view names there.
6161
*
@@ -214,7 +214,7 @@ protected String getContentType() {
214214
* interpreted as relative to the web application root, i.e. the context
215215
* path will be prepended to the URL.
216216
* <p><b>Redirect URLs can be specified via the "redirect:" prefix.</b>
217-
* E.g.: "redirect:myAction.do"
217+
* E.g.: "redirect:myAction"
218218
* @see RedirectView#setContextRelative
219219
* @see #REDIRECT_URL_PREFIX
220220
*/
@@ -241,7 +241,7 @@ protected boolean isRedirectContextRelative() {
241241
* difference. However, some clients depend on 303 when redirecting
242242
* after a POST request; turn this flag off in such a scenario.
243243
* <p><b>Redirect URLs can be specified via the "redirect:" prefix.</b>
244-
* E.g.: "redirect:myAction.do"
244+
* E.g.: "redirect:myAction"
245245
* @see RedirectView#setHttp10Compatible
246246
* @see #REDIRECT_URL_PREFIX
247247
*/
@@ -342,7 +342,7 @@ public Map<String, Object> getAttributesMap() {
342342
* <li>{@code true} - all Views resolved by this resolver will expose path variables
343343
* <li>{@code false} - no Views resolved by this resolver will expose path variables
344344
* <li>{@code null} - individual Views can decide for themselves (this is used by the default)
345-
* <ul>
345+
* </ul>
346346
* @see AbstractView#setExposePathVariables
347347
*/
348348
public void setExposePathVariables(Boolean exposePathVariables) {
@@ -453,18 +453,22 @@ protected View createView(String viewName, Locale locale) throws Exception {
453453
if (!canHandle(viewName, locale)) {
454454
return null;
455455
}
456+
456457
// Check for special "redirect:" prefix.
457458
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
458459
String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
459-
RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible());
460+
RedirectView view = new RedirectView(redirectUrl,
461+
isRedirectContextRelative(), isRedirectHttp10Compatible());
460462
view.setHosts(getRedirectHosts());
461-
return applyLifecycleMethods(viewName, view);
463+
return applyLifecycleMethods(REDIRECT_URL_PREFIX, view);
462464
}
465+
463466
// Check for special "forward:" prefix.
464467
if (viewName.startsWith(FORWARD_URL_PREFIX)) {
465468
String forwardUrl = viewName.substring(FORWARD_URL_PREFIX.length());
466469
return new InternalResourceView(forwardUrl);
467470
}
471+
468472
// Else fall back to superclass implementation: calling loadView.
469473
return super.createView(viewName, locale);
470474
}
@@ -486,7 +490,7 @@ protected boolean canHandle(String viewName, Locale locale) {
486490

487491
/**
488492
* Delegates to {@code buildView} for creating a new instance of the
489-
* specified view class, and applies the following Spring lifecycle methods
493+
* specified view class. Applies the following Spring lifecycle methods
490494
* (as supported by the generic Spring bean factory):
491495
* <ul>
492496
* <li>ApplicationContextAware's {@code setApplicationContext}
@@ -506,10 +510,6 @@ protected View loadView(String viewName, Locale locale) throws Exception {
506510
return (view.checkResource(locale) ? result : null);
507511
}
508512

509-
private View applyLifecycleMethods(String viewName, AbstractView view) {
510-
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
511-
}
512-
513513
/**
514514
* Creates a new View instance of the specified view class and configures it.
515515
* Does <i>not</i> perform any lookup for pre-defined View instances.
@@ -552,4 +552,8 @@ protected AbstractUrlBasedView buildView(String viewName) throws Exception {
552552
return view;
553553
}
554554

555+
private View applyLifecycleMethods(String viewName, AbstractView view) {
556+
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
557+
}
558+
555559
}

0 commit comments

Comments
 (0)