web应用要部署到web容器处理网络请求。比较常见的容器有tomcat和jetty,这两个都可以称作servlet容器。

        web应用部署文件是war包,war是web-archive文件的缩写。

        war包里面有web.xml文件,被称作是web应用描述文件,容器根据web.xml文件的基本配置启动web应用。

        很久之前servlet容器中处理业务逻辑的都是Servlet类,而不是现在各种POJO代码。

        接口Servlet有三个方法 1:init(ServletConfig config),构造方法,2:destory(),3:service(ServletRequest,ServletResponse)

处理业务的是service()方法。

       ServletConfig对于单个servlet可见,是在web.xml中配置<servlet></servlet>中的子配置<init-param></init-param>中配置

【Spring 设计思想】第0集-前期准备-Servlet知识点        

     ServletContext中存储的是整个web应用的启动配置,对于应用内的Servlet都可见,ServletContext也是在web.xml中的配置项。

【Spring 设计思想】第0集-前期准备-Servlet知识点

在web容器启动的时候,如果部署的是war包,那就会首先查找web.xml,创建ServletContext对象,读取web.xml中的配置,读取完之后容器会广播ServletContextEvent.

       ServletContextEvent有构造方法,ServletContextEvent(ServletContext context);

如果我们对容器启动事件感兴趣,就可以通过监听ServletContextEvent事件,来做一些web启动之前的准备工作,那监听的接口就是ServletContextEventListener;

     ServletContextEventListener接口有两个方法:

     1:contextInitlialized(ServletContextEvent event),2:contextDestroyed(ServletContext event);从方法的名字我们就知道,一个上下文创建成功,一个是上下文失效。在web应用启动时和关闭时调用。

这样我们就知道我们Spring框架在启动之前web容器做了什么,什么时候spring框架启动,以及Spring框架启动时做了什么。

参考资料:易百教程-servlet教程

 

    

相关文章:

  • 2021-06-10
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2022-02-25
猜你喜欢
  • 2021-12-03
  • 2021-11-23
  • 2021-05-19
  • 2021-05-23
  • 2022-12-23
  • 2021-08-21
  • 2021-10-15
相关资源
相似解决方案