类 ServletWrappingController

java.lang.Object
cn.taketoday.context.support.ApplicationObjectSupport
cn.taketoday.web.WebContentGenerator
cn.taketoday.web.handler.mvc.AbstractController
cn.taketoday.web.handler.mvc.ServletWrappingController
所有已实现的接口:
cn.taketoday.beans.factory.Aware, cn.taketoday.beans.factory.BeanNameAware, cn.taketoday.beans.factory.DisposableBean, cn.taketoday.beans.factory.InitializingBean, cn.taketoday.context.ApplicationContextAware, Controller, HttpRequestHandler, ServletContextAware

public class ServletWrappingController extends AbstractController implements cn.taketoday.beans.factory.BeanNameAware, cn.taketoday.beans.factory.InitializingBean, cn.taketoday.beans.factory.DisposableBean, ServletContextAware
Framework 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 Framework's dispatching infrastructure, for example to apply Framework 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="strutsWrappingController" class="cn.taketoday.web.handler.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>
从以下版本开始:
4.0 2022/2/8 17:18
作者:
Juergen Hoeller, Harry Yang
另请参阅:
  • 字段详细资料

    • servletClass

      @Nullable private Class<? extends Servlet> servletClass
    • servletName

      @Nullable private String servletName
    • initParameters

      private Properties initParameters
    • beanName

      @Nullable private String beanName
    • servletInstance

      @Nullable private Servlet servletInstance
    • servletContext

      private ServletContext servletContext
  • 构造器详细资料

    • ServletWrappingController

      public ServletWrappingController()
  • 方法详细资料

    • setServletClass

      public void setServletClass(@Nullable Class<? extends Servlet> servletClass)
      Set the class of the servlet to wrap. Needs to implement jakarta.servlet.Servlet.
      另请参阅:
    • setServletName

      public void setServletName(@Nullable 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(@Nullable String name)
      指定者:
      setBeanName 在接口中 cn.taketoday.beans.factory.BeanNameAware
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Initialize the wrapped Servlet instance.
      指定者:
      afterPropertiesSet 在接口中 cn.taketoday.beans.factory.InitializingBean
      抛出:
      Exception
      另请参阅:
    • handleRequestInternal

      protected ModelAndView handleRequestInternal(RequestContext request) throws Exception
      Invoke the wrapped Servlet instance.
      指定者:
      handleRequestInternal 在类中 AbstractController
      抛出:
      Exception
      另请参阅:
    • destroy

      public void destroy()
      Destroy the wrapped Servlet instance.
      指定者:
      destroy 在接口中 cn.taketoday.beans.factory.DisposableBean
      另请参阅:
    • setServletContext

      public void setServletContext(ServletContext servletContext)
      从接口复制的说明: ServletContextAware
      Set the ServletContext that this object runs in.

      Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.

      指定者:
      setServletContext 在接口中 ServletContextAware
      参数:
      servletContext - the ServletContext object to be used by this object
      另请参阅:
      • InitializingBean.afterPropertiesSet()
      • ApplicationContextAware.setApplicationContext(cn.taketoday.context.ApplicationContext)
    • getServletContext

      public ServletContext getServletContext()