Analysis of servlet working principle — reprint

Original text: http://www.ibm.com/developerworks/cn/java/j-lo-servlet/index.html?ca=drs -

Web technology has become one of the mainstream Internet web application technologies, and servlet is the core foundation of Java Web technology. Therefore, mastering the working principle of servlet is the basic requirement for becoming a qualified Java Web technology developer. This article will take you to understand how Java Web technology works based on servlet. You will know: take Tomcat as an example to understand how servlet container works? How does a web project start in the servlet container? How does the servlet container parse your web Servlet defined in XML? How are user requests assigned to the specified servlet? How does the servlet container manage the servlet lifecycle? You will also learn about the class hierarchy of the latest servlet API and the analysis of some difficult problems in servlet.

To introduce servlets, you must first clarify the servlet container. The relationship between servlets and servlet containers is a bit like the relationship between guns and bullets. Guns are born for bullets, and bullets make guns lethal. Although they are interdependent, they develop independently of each other. All this is to adapt to the results of industrial production. From a technical point of view, it is to decouple and cooperate with each other through standardized interfaces. Since interfaces are the key to connecting servlets and servlet containers, let's start with their interfaces. As mentioned earlier, servlet container is an independently developed standardized product. At present, it has many kinds, but they all have their own market positioning. It is difficult to say who is good and who is bad, and each has its own characteristics. For example, jetty, which is popular now, has made good progress in customization and mobile. Here we take Tomcat as an example to introduce how the servlet container manages servlets. Tomcat itself is also very complex. We only introduce it from the interface between servlet and servlet container. For a detailed introduction to tomcat, please refer to my other article Tomcat system architecture and pattern design analysis. In the container level of tomcat, the context container directly manages the wrapper class wrapper of the servlet in the container, so how the context container runs will directly affect the working mode of the servlet.

As can be seen from the above figure, Tomcat's containers are divided into four levels. The container that really manages servlets is the context container. A context corresponds to a web project. This can be easily found in Tomcat's configuration file, as follows:
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>