|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.servlet.view.AbstractView org.springframework.web.servlet.view.AbstractUrlBasedView org.springframework.web.servlet.view.InternalResourceView
public class InternalResourceView
Wrapper for a JSP or other resource within the same web application. Exposes model objects as request attributes and forwards the request to the specified resource URL using a RequestDispatcher.
A URL for this view is supposed to specify a resource within the web
application, suitable for RequestDispatcher's forward
or
include
method.
If operating within an already included request or within a response that
has already been committed, this view will fall back to an include instead of
a forward. This can be enforced by calling response.flushBuffer()
(which will commit the response) before rendering the view.
Typical usage with InternalResourceViewResolver would look as follows, from the perspective of the DispatcherServlet context definition:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean>Every view name returned from a handler will be translated to a JSP resource (for example: "myView" -> "/WEB-INF/jsp/myView.jsp"), using this view class by default.
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
,
RequestDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
,
ServletResponse.flushBuffer()
,
InternalResourceViewResolver
Field Summary |
---|
Fields inherited from class org.springframework.web.servlet.view.AbstractView |
---|
DEFAULT_CONTENT_TYPE |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
logger |
Constructor Summary | |
---|---|
InternalResourceView()
Constructor for use as a bean. |
|
InternalResourceView(String url)
Create a new InternalResourceView with the given URL. |
Method Summary | |
---|---|
protected void |
exposeForwardRequestAttributes(HttpServletRequest request)
Expose the current request URI and paths as HttpServletRequest
attributes under the keys defined in the Servlet 2.4 specification,
for Servlet 2.3- containers. |
protected void |
exposeHelpers(HttpServletRequest request)
Expose helpers unique to each rendering operation. |
protected String |
prepareForRendering(HttpServletRequest request,
HttpServletResponse response)
Prepare for rendering, and determine the request dispatcher path to forward to (or to include). |
protected void |
renderMergedOutputModel(Map model,
HttpServletRequest request,
HttpServletResponse response)
Render the internal resource given the specified model. |
protected boolean |
useInclude(HttpServletRequest request,
HttpServletResponse response)
Determine whether to use RequestDispatcher's include or
forward method. |
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView |
---|
afterPropertiesSet, getUrl, setUrl, toString |
Methods inherited from class org.springframework.web.servlet.view.AbstractView |
---|
addStaticAttribute, createRequestContext, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public InternalResourceView()
public InternalResourceView(String url)
url
- the URL to forward toMethod Detail |
---|
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception
renderMergedOutputModel
in class AbstractView
model
- combined output Map (never null
),
with dynamic values taking precedence over static attributesrequest
- current HTTP requestresponse
- current HTTP response
Exception
- if rendering failedprotected void exposeHelpers(HttpServletRequest request) throws Exception
Called by renderMergedOutputModel(Map, HttpServletRequest, HttpServletResponse)
.
The default implementation is empty. This method can be overridden to add
custom helpers as request attributes.
request
- current HTTP request
Exception
- if there's a fatal error while we're adding attributesrenderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,
JstlView.exposeHelpers(javax.servlet.http.HttpServletRequest)
,
TilesJstlView.exposeHelpers(javax.servlet.http.HttpServletRequest)
protected String prepareForRendering(HttpServletRequest request, HttpServletResponse response) throws Exception
This implementation simply returns the configured URL. Subclasses can override this to determine a resource to render, typically interpreting the URL in a different manner.
request
- current HTTP requestresponse
- current HTTP response
Exception
- if preparations failedAbstractUrlBasedView.getUrl()
,
TilesView.prepareForRendering(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response)
include
or
forward
method.
Performs a check whether an include URI attribute is found in the request, indicating an include request, and whether the response has already been committed. In both cases, an include will be performed, as a forward is not possible anymore.
request
- current HTTP requestresponse
- current HTTP response
true
for include, false
for forwardRequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
,
RequestDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
,
ServletResponse.isCommitted()
,
WebUtils.isIncludeRequest(javax.servlet.ServletRequest)
protected void exposeForwardRequestAttributes(HttpServletRequest request)
HttpServletRequest
attributes under the keys defined in the Servlet 2.4 specification,
for Servlet 2.3- containers.
Does not override values if already present, to not conflict with Servlet 2.4+ containers.
WebUtils.exposeForwardRequestAttributes(javax.servlet.http.HttpServletRequest)
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |