How A Servlet container Works

编程入门 行业动态 更新时间:2024-10-26 20:34:31

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:

  1. 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.
  2. 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.
  3. 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

本文发布于:2023-06-14 04:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1438326.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Servlet   container   Works

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!