public class ServletForwardingController extends AbstractController implements org.springframework.beans.factory.BeanNameAware
Useful to invoke an existing servlet via Spring's dispatching infrastructure, for example to apply Spring HandlerInterceptors to its requests. This will work even in a minimal Servlet container that does not support Servlet filters.
Example: web.xml, mapping all "/myservlet" requests to a Spring dispatcher. Also defines a custom "myServlet", but without servlet mapping.
<servlet> <servlet-name>myServlet</servlet-name> <servlet-class>mypackage.TestServlet</servlet-class> </servlet> <servlet> <servlet-name>myDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>myDispatcher</servlet-name> <url-pattern>/myservlet</url-pattern> </servlet-mapping>Example: myDispatcher-servlet.xml, in turn forwarding "/myservlet" to your servlet (identified by servlet name). All such requests will go through the configured HandlerInterceptor chain (e.g. an OpenSessionInViewInterceptor). From the servlet point of view, everything will work as usual.
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="interceptors"> <list> <ref bean="openSessionInViewInterceptor"/> </list> </property> <property name="mappings"> <props> <prop key="/myservlet">myServletForwardingController</prop> </props> </property> </bean> <bean id="myServletForwardingController" class="org.springframework.web.servlet.mvc.ServletForwardingController"> <property name="servletName"><value>myServlet</value></property> </bean>
ServletWrappingController
,
org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor
,
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
Constructor and Description |
---|
ServletForwardingController() |
Modifier and Type | Method and Description |
---|---|
protected ModelAndView |
handleRequestInternal(HttpServletRequest request,
HttpServletResponse response)
Template method.
|
void |
setBeanName(java.lang.String name) |
void |
setServletName(java.lang.String servletName)
Set the name of the servlet to forward to,
i.e.
|
protected boolean |
useInclude(HttpServletRequest request,
HttpServletResponse response)
Determine whether to use RequestDispatcher's
include or
forward method. |
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
public void setServletName(java.lang.String servletName)
Default is the bean name of this controller.
public void setBeanName(java.lang.String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
AbstractController
handleRequest
.handleRequestInternal
in class AbstractController
java.lang.Exception
AbstractController.handleRequest(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 responsetrue
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)