Top Description Inners Fields Constructors Methods
org.springframework.web.servlet.mvc

public Class ServletWrappingController

extends AbstractController
implements BeanNameAware, InitializingBean, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.Aware
Imports
java.util.Enumeration, .Properties, jakarta.servlet.Servlet, .ServletConfig, .ServletContext, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.beans.factory.BeanNameAware, .DisposableBean, .InitializingBean, org.springframework.lang.Nullable, org.springframework.util.Assert, .ReflectionUtils, org.springframework.web.servlet.ModelAndView

Spring Controller implementation that wraps a servlet instance which it manages internally. Such a wrapped servlet is not known outside 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">
    <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>
Author
Juergen Hoeller
Since
1.1.1
See Also
ServletForwardingController

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
ServletWrappingController.DelegatingServletConfig

Internal implementation of the ServletConfig interface, to be passed to the wrapped servlet.

Field Summary

Modifier and TypeField and Description
private String
private Properties
private Class<? extends Servlet>
private Servlet
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Destroy the wrapped Servlet instance.

protected ModelAndView
public void
setBeanName(String
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.
name
)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Set the name of the bean in the bean factory that created this bean.

public void
setInitParameters(Properties initParameters)

Specify init parameters for the servlet to wrap, as name-value pairs.

public void
setServletClass(Class<? extends Servlet> servletClass)

Set the class of the servlet to wrap.

public void
setServletName(String servletName)

Set the name of the servlet to wrap.

Inherited from org.springframework.web.servlet.mvc.AbstractController:
handleRequestisSynchronizeOnSessionsetSynchronizeOnSession

Field Detail

beanNameback to summary
private String beanName
Annotations
@Nullable
initParametersback to summary
private Properties initParameters
servletClassback to summary
private Class<? extends Servlet> servletClass
Annotations
@Nullable
servletInstanceback to summary
private Servlet servletInstance
Annotations
@Nullable
servletNameback to summary
private String servletName
Annotations
@Nullable

Constructor Detail

ServletWrappingControllerback to summary
public ServletWrappingController()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws Exception

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Initialize the wrapped Servlet instance.

Annotations
@Override
Exceptions
Exception:

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason

See Also
jakarta.servlet.Servlet#init(jakarta.servlet.ServletConfig)
destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Destroy the wrapped Servlet instance.

Annotations
@Override
See Also
jakarta.servlet.Servlet#destroy()
handleRequestInternalback to summary
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception

Implements abstract org.springframework.web.servlet.mvc.AbstractController.handleRequestInternal.

Invoke the wrapped Servlet instance.

Annotations
@Override
See Also
jakarta.servlet.Servlet#service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
setBeanNameback to summary
public void setBeanName(String name)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Doc from org.springframework.beans.factory.BeanNameAware.setBeanName.

Set 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.

Parameters
name:String

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.

Annotations
@Override
setInitParametersback to summary
public void setInitParameters(Properties initParameters)

Specify init parameters for the servlet to wrap, as name-value pairs.

setServletClassback to summary
public void setServletClass(Class<? extends Servlet> servletClass)

Set the class of the servlet to wrap. Needs to implement jakarta.servlet.Servlet.

See Also
jakarta.servlet.Servlet
setServletNameback to summary
public void setServletName(String servletName)

Set the name of the servlet to wrap. Default is the bean name of this controller.

org.springframework.web.servlet.mvc back to summary

private Class ServletWrappingController.DelegatingServletConfig

extends Object
implements ServletConfig
Class Inheritance
  • java.lang.Object
  • org.springframework.web.servlet.mvc.ServletWrappingController.DelegatingServletConfig
All Implemented Interfaces
jakarta.servlet.ServletConfig

Internal implementation of the ServletConfig interface, to be passed to the wrapped servlet. Delegates to ServletWrappingController fields and methods to provide init parameters and other environment info.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
getInitParameter(String
a String specifying the name of the initialization parameter
paramName
)

Implements jakarta.servlet.ServletConfig.getInitParameter.

Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

public Enumeration<String>
getInitParameterNames()

Implements jakarta.servlet.ServletConfig.getInitParameterNames.

Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.

public ServletContext
getServletContext()

Implements jakarta.servlet.ServletConfig.getServletContext.

Returns a reference to the ServletContext in which the caller is executing.

public String
getServletName()

Implements jakarta.servlet.ServletConfig.getServletName.

Returns the name of this servlet instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DelegatingServletConfigback to summary
private DelegatingServletConfig()

Method Detail

getInitParameterback to summary
public String getInitParameter(String paramName)

Implements jakarta.servlet.ServletConfig.getInitParameter.

Doc from jakarta.servlet.ServletConfig.getInitParameter.

Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

Parameters
paramName:String

a String specifying the name of the initialization parameter

Returns:String

a String containing the value of the initialization parameter

Annotations
@Override
getInitParameterNamesback to summary
public Enumeration<String> getInitParameterNames()

Implements jakarta.servlet.ServletConfig.getInitParameterNames.

Doc from jakarta.servlet.ServletConfig.getInitParameterNames.

Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.

Returns:Enumeration<String>

an Enumeration of String objects containing the names of the servlet's initialization parameters

Annotations
@Override
@SuppressWarnings:rawtypes, unchecked
getServletContextback to summary
public ServletContext getServletContext()

Implements jakarta.servlet.ServletConfig.getServletContext.

Doc from jakarta.servlet.ServletConfig.getServletContext.

Returns a reference to the ServletContext in which the caller is executing.

Returns:ServletContext

a ServletContext object, used by the caller to interact with its servlet container

Annotations
@Override
@Nullable
getServletNameback to summary
public String getServletName()

Implements jakarta.servlet.ServletConfig.getServletName.

Doc from jakarta.servlet.ServletConfig.getServletName.

Returns the name of this servlet instance. The name may be provided via server administration, assigned in the web application deployment descriptor, or for an unregistered (and thus unnamed) servlet instance it will be the servlet's class name.

Returns:String

the name of the servlet instance

Annotations
@Override
@Nullable