|
|||||||||||
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.support.WebContentGenerator org.springframework.web.servlet.mvc.AbstractController org.springframework.web.servlet.mvc.ServletForwardingController
Spring Controller implementation that forwards to a named servlet, i.e. the "servlet-name" in web.xml rather than a URL path mapping. A target servlet doesn't even need a "servlet-mapping" in web.xml in the first place: A "servlet" declaration is sufficient.
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 Servlet 2.2 container that does not support Servlet filters.
In particular, the main intent of this controller is to allow for applying Spring's OpenSessionInViewInterceptor or OpenPersistenceManagerInViewInterceptor to servlets in a Servlet 2.2 container. The specified "servlet-name" will simply refer to a custom servlet definition in web.xml in such a scenario. You then need to map "/myservlet" (or whatever path you choose for your servlet) onto this controller, which will in turn forward to your servlet.
In a Servlet 2.3 container, when not using Spring's own web MVC framework, it is recommended to use classic servlet mapping in combination with a filter, for example Spring's OpenSessionInViewFilter or OpenPersistenceManagerInViewFilter.
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
,
OpenSessionInViewInterceptor
,
OpenSessionInViewFilter
,
OpenPersistenceManagerInViewInterceptor
,
OpenPersistenceManagerInViewFilter
Field Summary |
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator |
HEADER_CACHE_CONTROL, HEADER_EXPIRES, HEADER_PRAGMA, METHOD_GET, METHOD_HEAD, METHOD_POST |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
logger |
Constructor Summary | |
ServletForwardingController()
|
Method Summary | |
protected ModelAndView |
handleRequestInternal(HttpServletRequest request,
HttpServletResponse response)
Template method. |
protected void |
initApplicationContext()
Subclasses can override this for custom initialization behavior. |
void |
setBeanName(String name)
Set the name of the bean in the bean factory that created this bean. |
void |
setServletName(String servletName)
Set the name of the servlet to forward to, i.e. the "servlet-name" of the target servlet in web.xml. |
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController |
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession |
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator |
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
getServletContext, getTempDir, getWebApplicationContext, isContextRequired |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ServletForwardingController()
Method Detail |
public void setServletName(String servletName)
Default is the bean name of this controller.
public void setBeanName(String name)
BeanNameAware
Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method.
setBeanName
in interface BeanNameAware
name
- the name of the bean in the factoryprotected void initApplicationContext()
ApplicationObjectSupport
setApplicationContext
after setting the context instance.
Note: Does not get called on reinitialization of the context but rather just on first initialization of this object's context reference.
initApplicationContext
in class ApplicationObjectSupport
ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception
AbstractController
handleRequestInternal
in class AbstractController
Exception
AbstractController.handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |