Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is Tomcat a Servlet container?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "whether Tomcat is a Servlet container". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "whether Tomcat is a Servlet container".

Context

As the name implies, the Servlet container is used to load and store Servlet.

A Servlet represents a program running on the server (servlet = server + applet). If users want to use this program, they need to send a request to the program and get the response of the program, that is, ServletRequest and ServletResponse in the Servlet specification.

So Servlet is actually a specification used in Java to handle requests, so we usually have one or more Servlet in our project, which is responsible for receiving the request or transferring the request to other business logic.

So we have a DispatcherServlet for both Spring MVC and Spring Boot (a Servlet with similar function, which is responsible for receiving requests).

So, usually Servlet belongs to an application (project), in other words, one of our applications contains multiple Servlet, so this is the second layer of Servlet container-the application, that is, the Context (application context) in Tomcat. What about the first layer of Servlet containers?

Wrapper

Wrapper is the first layer of Servlet container, and Wrapper represents the wrapper of Servlet, so it is closest to Servlet, so why do you need Wrapper?

We usually think of Wrapper as follows:

One Wrapper corresponds to one Servlet. If you think of it this way, you really don't need a Wrapper, but there are some other situations we need to consider:

For example, Filter, a Filter can correspond to a Servlet.

For example, ServletPool, the usual Servlet is common to all requesting threads, but in Servlet, each requesting thread is allowed to use a separate instance of Servlet.

So in Wrapper, it includes not only a Servlet, but also a filter and a Servlet pool, so Wrapper is the first layer Servlet container.

Host

In our real life, an application is deployed on a single host, so a host can contain multiple applications, and an application contains multiple Servlet, so Host is the third layer container.

In Tomcat, Host represents a virtual host. When Tomcat processes a request, it can go to the corresponding Host according to the requested domain name for processing.

Engine

Host manages Context,Context manages Wrapper,Wrapper manages Servlet and Engine is used to manage Host. So Engine is the fourth layer container.

Last

Someone must be in doubt, so you don't need a container on top of Engine? You don't need it? For example:

We should put our money (Servlet) in the Wrapper, the wallet in the Context, the schoolbag in the Host, and the suitcase on the Engine.

So, if you ask me, "where do I put the Engine?" It's like asking me, "where do I put the plane?"

The answer is that higher-level containers are no longer needed because they are no longer necessary.

Summary

In Tomcat, containers are divided into:

Wrapper

Context

Host

Engine

Thank you for reading, the above is the content of "Tomcat is not a Servlet container". After the study of this article, I believe you have a deeper understanding of whether Tomcat is a Servlet container, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report