admin管理员组文章数量:1648597
Excerpted from <How Tomcat works>.
A servlet container is a complex system. However, basically there are three things that a servlet container does to service a request for a servlet:
- Creating a requestion instance and populate it with information that may be used by the invoked servlet, such as parameters, headers, cookies, query string, URI, etc. A request object is an instance of javax.servlet.ServletRequest interface or the javex.servlet.http.ServletRequest interface.
- Creating a response object that the invoked servlet uses to send the response to the web client. A response object is an instance of the javax.servlet.ServletResponse interface or the javax.servlet.http.ServletResponse interface.
- Invoking the service method of the servlet, passing the request and response objects. Here the sevlet reads the values from the request object and writes to the response object.
Simplistic Block Diagram
The connector is there to connect a request with the container. Its job is to construct a request object and a reponse object for each HTTP request it receives. It then passes processing to the container. The container receives the request and response objects from the connector and is responsible for invoking the servlet's method.
Let's examine servlet programming from a servlet container's perspective. In a nutshell, a fully-functional servlet container does the following for each HTTP request for a servlet:
- When the servlet is called for the first time, load the servlet class and call the servlet's init method (once only).
- For each request, construct an instance of javax.servletServletRequest and and instance of javax.servlet.ServletResponse.
- Invoke the servlet's service method, passing the ServletRequest and ServletResponse object.
- When the servlet class is shut down, call the servlet's destroy methodand unload the servlet class.
版权声明:本文标题:How A Servlet container Works 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729494514a1202778.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论