Explore the functions of servlets and Servlets

Source: Internet
Author: User

First, we need to understand what Server,server refers to any computer and cluster that allows users to file access, print, communicate, and other services on the network.

A servlet is a program written by Java on the server side that is similar to a problem-solving center, independent of the client and the server, regardless of the protocol and Platform.

The servlet runs in java-enabled Web server, which is known in the previous definition of server as the server server, and its primary function is to allow users to access, print, communicate and other services of the computer, more on the hardware of the connection section , and the Java servlet can dynamically extend the capabilities of the server as if it were adding plugins or components to the server and providing Web services in Request-response mode.

The main function of a servlet is to interactively browse and modify data to generate dynamic Web content. This process is:

The client sends the request to the server side;

The server sends the request information to the servlet;

Depending on the client's request, the servlet dynamically generates the response content and passes it to the server;

The server returns the response to the client.

Before the servlet appears, the client and server Exchange data, but the function is scarce, can not satisfy the function requested by the client, then people think of a way, through a third-party things to deal with this unresolved problem, the Java Servle appears, the client "user" Send the request to Server,server will not be able to handle the problem thrown to the "subordinate" servlet to complete, and then "subordinate" after the completion of the results to the server "Boss", "Boss" in the processing results on the title to the "user".

If the "Boss" is not satisfied with the skill level of the subordinate, then he can learn new knowledge, which means that the function of the servlet can be expanded dynamically and even be replaced by a "subordinate".

The servlet needs to know only how to be responsible for the "boss", how to communicate with the "Boss", and processing requests, so for the server, need an interface package, it can be said as a Java program, the need for an API interface, in addition, many times the servlet can be learned, He shared the server's task, so that we do not have to add functionality directly on the server, only one interface, so that the development of the difficulty greatly reduced, but also reduce the complexity of maintenance.

The servlet, like a clerk, helps the boss to communicate and communicate with other departments or staff. Servlets can interact with files, databases, applets, Java applications, and so on, and then return data to the server to satisfy client requests, and the server can authorize the servlet to access many resources, such as accessing the database to store the response client's information, and so on.

In addition, the servlet can proliferate itself, or communicate with more servlets, like a small group, which greatly strengthens its functionality.

We know that the servlet has the following life cycle:

Server creates an instance of the servlet;

The server calls the servlet's init () method;

The client's request arrives at the server;

The server creates the request object;

The server creates the response object;

The server activates the service () method of the servlet and then passes the request with the response object as a parameter;

The service () method obtains information about the requested object, processes the request, accesses other resources (such as a database), and obtains the required information;

The service () method uses the method of the response object to pass the response back to the Server,server Crown name and eventually to the client.

In addition, the service () method may activate other methods to process the request, such as doget () or dopost () or a new method created by the programmer.

So for more client requests, the server creates a new request and response object, and still activates the servlet's service () method, passing multiple objects as parameters to it. This is done by repeating the 1~8 loop processing, but without calling the Init () method again. After the servlet is initialized, the "boss" sees that its "subordinate" does not need to complete the task, at this point, the server calls the servlet's Destroy () method, "subordinate" on the holiday.

Explore the functions of servlets and Servlets

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.