First Knowledge servlet

Source: Internet
Author: User

In the course of learning Java programming, a servlet class was encountered. In the beginning, these concepts are not particularly understood, the impression is not very deep. But the servlet is a class that we have to think about to learn java. Therefore, a basic introduction and summary, in order to deepen the impression and understanding of it.

What is a servlet?

In fact, it is a class, written in Java program, the program needs to be based on the HTTP protocol, follow the servlet specification. It can be said to be a bridge between a Web browser or an HTTP client and a server database or application. In this case, it can also be linked to the previously learned three-tier architecture as a middle tier for communication between the client and server.

What's the effect?

It can receive data and requests from the client, process it, then pass it to the server-side database and pass the results back to the client.

the life cycle of the servlet

The life cycle of a servlet can be divided into three phases:

First Stage: initialization phase

The servlet is loaded and instantiated by starting the servlet container, in which the data in the. class file is read into memory. It then creates a Servlet object and finally implements the initialization by invoking the Servlet object's init method. In this process, the Init method executes only once. The initialization process is only loaded once, no matter how many times the servlet is called.

Phase II: operational phase

After the Servlet object is initialized, the ServletRequest and Servletresponse objects are created based on the client's request, and then the service method is called. And pass these two parameters to the service method. The service method obtains the requested information through the ServletRequest object and processes the request. The response result of this request is then generated by the Servletresponse object, and the result is returned to the client.

Phase III: Destruction phase

When the service terminates, the servlet container invokes the Destroy method to implement destroying the Servlet object, freeing the resource. This method is also performed only once.


Summary:

The most important process for a servlet is to receive client requests and Servletresponse objects from the ServletRequest object to return the information to the client. Then we can understand and grasp the process, and then compare with some of the previously learned layered knowledge, and find that it is not as difficult to understand as it started. Of course, the understanding of the servlet is only a fur, but also need to continue to deepen learning.

First Knowledge servlet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.