Class ServletWrappingController
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
,org.springframework.web.context.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 (for example, 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 Summary
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Initialize the wrapped Servlet instance.void
destroy()
Destroy the wrapped Servlet instance.protected ModelAndView
handleRequestInternal
(HttpServletRequest request, HttpServletResponse response) Invoke the wrapped Servlet instance.void
setBeanName
(String name) void
setInitParameters
(Properties initParameters) Specify init parameters for the servlet to wrap, as name-value pairs.void
setServletClass
(Class<? extends Servlet> servletClass) Set the class of the servlet to wrap.void
setServletName
(String servletName) Set the name of the servlet to wrap.Methods inherited from class org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator
applyCacheControl, applyCacheSeconds, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isRequireSession, prepareResponse, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setVaryByRequestHeaders
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
-
Constructor Details
-
ServletWrappingController
public ServletWrappingController()
-
-
Method Details
-
setServletClass
Set the class of the servlet to wrap. Needs to implementjakarta.servlet.Servlet
.- See Also:
-
setServletName
Set the name of the servlet to wrap. Default is the bean name of this controller. -
setInitParameters
Specify init parameters for the servlet to wrap, as name-value pairs. -
setBeanName
- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
-
afterPropertiesSet
Initialize the wrapped Servlet instance.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
- See Also:
-
handleRequestInternal
@Nullable protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception Invoke the wrapped Servlet instance.- Specified by:
handleRequestInternal
in classAbstractController
- Throws:
Exception
- See Also:
-
destroy
public void destroy()Destroy the wrapped Servlet instance.- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- See Also:
-