servlet 是应用程序
Servlet应用程序如何工作 (How a Servlet Application works)
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)
-
-
deployment descriptor and creates two objects :
部署描述符找到servlet并创建两个对象:
- HttpServletRequestHttpServletRequest
- HttpServletResponseHttpServletResponse
-
service()method and passes theservice()方法并将request, response objects as arguments. 请求,响应对象作为参数传递。 - The
doGet()ordoPost()to call, based on HTTP Request Method(Get, Post etc) sent by the client. Suppose the client sent an HTTP GET request, so theservice()will call Servlet'sdoGet()method. - 然后, HTTP请求方法 (Get,Post等)确定要调用的servlet方法
doGet()或doPost()。 假设客户端发送了一个HTTP GET请求,那么service()将调用Servlet的doGet()方法。 -
-
service()method is completed theservice()方法完成之后, thread dies. And the request and response objects are ready for 线程死亡。 并且请求和响应对象已准备好进行garbage collection. 垃圾回收 。
翻译自: https://www.studytonight.com/servlet/how-a-servlet-application-work.php
servlet 是应用程序