类 ServletWrappingController
- 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.ServletWrappingController
- 所有已实现的接口:
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 toServletForwardingController
).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>
- 从以下版本开始:
- 1.1.1
- 作者:
- Juergen Hoeller
- 另请参阅:
ServletForwardingController
字段概要
从类继承的字段 org.springframework.web.servlet.support.WebContentGenerator
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
构造器概要
构造器 构造器 说明 ServletWrappingController()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
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)
Set the name of the bean in the bean factory that created this bean.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.从类继承的方法 org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
从类继承的方法 org.springframework.web.servlet.support.WebContentGenerator
applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
构造器详细资料
ServletWrappingController
public ServletWrappingController()
方法详细资料
setServletClass
public void setServletClass(Class<? extends Servlet> servletClass)
Set the class of the servlet to wrap. Needs to implementjavax.servlet.Servlet
.- 另请参阅:
Servlet
setServletName
public void setServletName(String servletName)
Set the name of the servlet to wrap. Default is the bean name of this controller.
setInitParameters
public void setInitParameters(Properties initParameters)
Specify init parameters for the servlet to wrap, as name-value pairs.
setBeanName
public void setBeanName(String name)
从接口复制的说明:BeanNameAware
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.- 指定者:
setBeanName
在接口中BeanNameAware
- 参数:
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 theBeanFactoryUtils.originalBeanName(String)
method to extract the original bean name (without suffix), if desired.
afterPropertiesSet
public void afterPropertiesSet() throws Exception
Initialize the wrapped Servlet instance.- 指定者:
afterPropertiesSet
在接口中InitializingBean
- 抛出:
Exception
- in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason- 另请参阅:
Servlet.init(javax.servlet.ServletConfig)
handleRequestInternal
protected HttpServletResponse response) throws Exception
Invoke the wrapped Servlet instance.
destroy
public void destroy()
Destroy the wrapped Servlet instance.- 指定者:
destroy
在接口中DisposableBean
- 另请参阅:
Servlet.destroy()