Class ServletWrappingController

All Implemented Interfaces:
Aware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ServletContextAware, Controller

public class ServletWrappingController extends AbstractController implements BeanNameAware, InitializingBean, DisposableBean
Spring Controller implementation that wraps a servlet instance which it manages internally. Such a wrapped servlet is not known outside of this controller; its entire lifecycle is covered here (in contrast to ServletForwardingController).

Useful to invoke an existing servlet via Spring's dispatching infrastructure, for example to apply Spring HandlerInterceptors to its requests.

Note that Struts has a special requirement in that it parses web.xml to find its servlet mapping. Therefore, you need to specify the DispatcherServlet's servlet name as "servletName" on this controller, so that Struts finds the DispatcherServlet's mapping (thinking that it refers to the ActionServlet).

Example: a DispatcherServlet XML context, forwarding "*.do" to the Struts ActionServlet wrapped by a ServletWrappingController. All such requests will go through the configured HandlerInterceptor chain (e.g. an OpenSessionInViewInterceptor). From the Struts point of view, everything will work as usual.

 <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
   <property name="interceptors">
       <ref bean="openSessionInViewInterceptor"/>
   <property name="mappings">
       <prop key="*.do">strutsWrappingController</prop>

 <bean id="strutsWrappingController" class="org.springframework.web.servlet.mvc.ServletWrappingController">
   <property name="servletClass">
   <property name="servletName">
   <property name="initParameters">
       <prop key="config">/WEB-INF/struts-config.xml</prop>
Juergen Hoeller
See Also: