How A Servlet container 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

SimplisticBlockDiagram

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值