From 101a5cd8ff6cd307cfcff08db31c62ae8e9b0082 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 22 Apr 2010 21:46:56 +0000 Subject: [PATCH] factored out getRequestDispatcher template method (SPR-7118) --- .../servlet/view/InternalResourceView.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java index 3a84342a1a5..36f0af33aed 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -214,10 +214,10 @@ public class InternalResourceView extends AbstractUrlBasedView { String dispatcherPath = prepareForRendering(requestToExpose, response); // Obtain a RequestDispatcher for the target resource (typically a JSP). - RequestDispatcher rd = requestToExpose.getRequestDispatcher(dispatcherPath); + RequestDispatcher rd = getRequestDispatcher(requestToExpose, dispatcherPath); if (rd == null) { - throw new ServletException( - "Could not get RequestDispatcher for [" + getUrl() + "]: check that this file exists within your WAR"); + throw new ServletException("Could not get RequestDispatcher for [" + getUrl() + + "]: Check that the corresponding file exists within your web application archive!"); } // If already included or response already committed, perform include, else forward. @@ -239,6 +239,23 @@ public class InternalResourceView extends AbstractUrlBasedView { } } + /** + * Get the request handle to expose to the RequestDispatcher, i.e. to the view. + *

The default implementation wraps the original request for exposure of + * Spring beans as request attributes (if demanded). + * @param originalRequest the original servlet request as provided by the engine + * @return the wrapped request, or the original request if no wrapping is necessary + * @see #setExposeContextBeansAsAttributes + * @see org.springframework.web.context.support.ContextExposingHttpServletRequest + */ + protected HttpServletRequest getRequestToExpose(HttpServletRequest originalRequest) { + if (this.exposeContextBeansAsAttributes || this.exposedContextBeanNames != null) { + return new ContextExposingHttpServletRequest( + originalRequest, getWebApplicationContext(), this.exposedContextBeanNames); + } + return originalRequest; + } + /** * Expose helpers unique to each rendering operation. This is necessary so that * different rendering operations can't overwrite each other's contexts etc. @@ -281,20 +298,16 @@ public class InternalResourceView extends AbstractUrlBasedView { } /** - * Get the request handle to expose to the RequestDispatcher, i.e. to the view. - *

The default implementation wraps the original request for exposure of - * Spring beans as request attributes (if demanded). - * @param originalRequest the original servlet request as provided by the engine - * @return the wrapped request, or the original request if no wrapping is necessary - * @see #setExposeContextBeansAsAttributes - * @see org.springframework.web.context.support.ContextExposingHttpServletRequest + * Obtain the RequestDispatcher to use for the forward/include. + *

The default implementation simply calls + * {@link HttpServletRequest#getRequestDispatcher(String)}. + * Can be overridden in subclasses. + * @param request current HTTP request + * @param path the target URL (as returned from {@link #prepareForRendering}) + * @return a corresponding RequestDispatcher */ - protected HttpServletRequest getRequestToExpose(HttpServletRequest originalRequest) { - if (this.exposeContextBeansAsAttributes || this.exposedContextBeanNames != null) { - return new ContextExposingHttpServletRequest( - originalRequest, getWebApplicationContext(), this.exposedContextBeanNames); - } - return originalRequest; + protected RequestDispatcher getRequestDispatcher(HttpServletRequest request, String path) { + return request.getRequestDispatcher(path); } /**