Class ServletWrappingController
- All Implemented Interfaces:
- Aware,- BeanNameAware,- DisposableBean,- InitializingBean,- ApplicationContextAware,- ServletContextAware,- Controller
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">
     <list>
       <ref bean="openSessionInViewInterceptor"/>
     </list>
   </property>
   <property name="mappings">
     <props>
       <prop key="*.do">strutsWrappingController</prop>
     </props>
   </property>
 </bean>
 <bean id="strutsWrappingController" class="org.springframework.web.servlet.mvc.ServletWrappingController">
   <property name="servletClass">
     <value>org.apache.struts.action.ActionServlet</value>
   </property>
   <property name="servletName">
     <value>action</value>
   </property>
   <property name="initParameters">
     <props>
       <prop key="config">/WEB-INF/struts-config.xml</prop>
     </props>
   </property>
 </bean>- Since:
- 1.1.1
- Author:
- Juergen Hoeller
- See Also:
- 
Field SummaryFields inherited from class org.springframework.web.servlet.support.WebContentGeneratorHEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POSTFields inherited from class org.springframework.context.support.ApplicationObjectSupportlogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidInitialize the wrapped Servlet instance.voiddestroy()Destroy the wrapped Servlet instance.protected ModelAndViewhandleRequestInternal(HttpServletRequest request, HttpServletResponse response) Invoke the wrapped Servlet instance.voidsetBeanName(String name) Set the name of the bean in the bean factory that created this bean.voidsetInitParameters(Properties initParameters) Specify init parameters for the servlet to wrap, as name-value pairs.voidsetServletClass(Class<? extends Servlet> servletClass) Set the class of the servlet to wrap.voidsetServletName(String servletName) Set the name of the servlet to wrap.Methods inherited from class org.springframework.web.servlet.mvc.AbstractControllerhandleRequest, isSynchronizeOnSession, setSynchronizeOnSessionMethods inherited from class org.springframework.web.servlet.support.WebContentGeneratorapplyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeadersMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Constructor Details- 
ServletWrappingControllerpublic ServletWrappingController()
 
- 
- 
Method Details- 
setServletClassSet the class of the servlet to wrap. Needs to implementjakarta.servlet.Servlet.- See Also:
 
- 
setServletNameSet the name of the servlet to wrap. Default is the bean name of this controller.
- 
setInitParametersSpecify init parameters for the servlet to wrap, as name-value pairs.
- 
setBeanNameDescription copied from interface:BeanNameAwareSet the name of the bean in the bean factory that created this bean.Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
- setBeanNamein interface- BeanNameAware
- Parameters:
- name- the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the- BeanFactoryUtils.originalBeanName(String)method to extract the original bean name (without suffix), if desired.
 
- 
afterPropertiesSetInitialize the wrapped Servlet instance.- Specified by:
- afterPropertiesSetin interface- InitializingBean
- Throws:
- Exception- in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
- See Also:
 
- 
handleRequestInternalprotected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception Invoke the wrapped Servlet instance.- Specified by:
- handleRequestInternalin class- AbstractController
- Throws:
- Exception
- See Also:
 
- 
destroypublic void destroy()Destroy the wrapped Servlet instance.- Specified by:
- destroyin interface- DisposableBean
- See Also:
 
 
-