servlet 是应用程序_Servlet应用程序如何工作

servlet 是应用程序

Web container is responsible for managing execution of servlets and JSP pages for Java EE application.

Web容器负责管理Java EE应用程序的servlet和JSP页面的执行。

When a request comes in for a servlet, the server hands the request to the Web Container. Web Container is responsible for instantiating the servlet or creating a new thread to handle the request. Its the job of Web Container to get the request and response to the servlet. The container creates multiple threads to process multiple requests to a single servlet.

当收到对Servlet的请求时,服务器会将请求移交给Web容器。 Web容器负责实例化servlet或创建一个新线程来处理请求。 Web容器的工作是获取对Servlet的请求和响应。 容器创建多个线程来处理对单个servlet的多个请求。

Servlets don't have a main() method. Web Container manages the life cycle of a Servlet instance.

Servlet没有main()方法 。 Web容器管理Servlet实例的生命周期。

Servlet工作原理快速修订 (Quick Revision on How a Servlet works)

  1. User sends request for a servlet by clicking a link that has URL to a servlet.

    用户通过单击具有指向Servlet的URL的链接来发送对Servlet的请求。

    how a servlet application works
  2. The container finds the servlet using deployment descriptor and creates two objects :

    容器使用部署描述符找到servlet并创建两个对象:

    1. HttpServletRequestHttpServletRequest
    2. HttpServletResponseHttpServletResponse
    Request and Response objects created while servlet execution
  3. Then the container creates or allocates a thread for that request and calls the Servlet's service() method and passes the request, response objects as arguments.

    然后,容器为该请求创建或分配线程,并调用Servlet的service()方法并将请求,响应对象作为参数传递。

    call to service() method with request and response object
  4. The service() method, then decides which servlet method, doGet() or doPost() to call, based on HTTP Request Method(Get, Post etc) sent by the client. Suppose the client sent an HTTP GET request, so the service() will call Servlet's doGet() method.

    然后, service()方法根据客户端发送的HTTP请求方法 (Get,Post等)确定要调用的servlet方法doGet()doPost() 。 假设客户端发送了一个HTTP GET请求,那么service()将调用Servlet的doGet()方法。

    call to doGet() or doPost() in Servlet execution
  5. Then the Servlet uses response object to write the response back to the client.

    然后,Servlet使用响应对象将响应写回到客户端。

    Sending back the response to the client after servlet execution
  6. After the service() method is completed the thread dies. And the request and response objects are ready for garbage collection.

    service()方法完成之后, 线程死亡。 并且请求和响应对象已准备好进行垃圾回收

    End of Servlet Execution

翻译自: https://www.studytonight.com/servlet/how-a-servlet-application-work.php

servlet 是应用程序

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值