What is servlet

xiaoxiao2021-03-06  73

Servlet is a Server-end program written in Java, which is independent of the protocol and platform. Servlet runs in Java-enabled Web Server. Java Servlets can dynamically extend Server's capabilities and use request-response mode to provide web services.

The earliest support of servlet technology is Java Web Server for Javasoft. Thereafter, some other Java-based Web Server begin to support standard servlet APIs. The main feature of the servlet is interactively browsing and modifying data, generating dynamic web content. This process is:

Client sends a request to the server side;

The server will send the request information to servlet

The servlet generates a response content and passes it to the Server. Response content dynamically generated, often depends on the client's request

The server returns the response to the client

Servlet looks like a usual Java program. Servlet imports a specific package that belongs to the Java Servlet API. Because it is an object word code, you can load from the network, you can say that servlet is just like Applets, however, due to servlets running in Server, they do not need a graphical user interface. From this perspective, servlet is also known as Faceless Object.

Advantages of Java Servlet:

Servlets can interact with other resources (files, databases, applets, java applications, etc.) to generate response to the client. You can also save the information during the response if needed.

With servlet, the server can fully authorize access to local resources (such as database), and servlet itself will control external users' access quantity and access nature.

The servlet can be a client program for other services, for example, in a distributed application, can activate the servlet from the remote hard drive from the remote drive from the local hard drive or over the network.

The servlet can be linked (chain). A servlet can call another or a series of servlets, which becomes its client.

With Servlet TAG technology, you can dynamically call servlets in the HTML page.

The Servlet API has nothing to do with the agreement. It does not have any assumptions to delivering its protocol.

Like all Java programs, servlet has all the advantages of object-oriented Java language.

Servlet provides all the advantages of Java applications - portable, robust, easy development. Using the Servlet's TAG technology, servlet can generate dynamic content embedded in a static HTML page.

A servlet is activated by the first request sent by the client, and then it will continue to run in the background, waiting for future request. Each request will generate a new thread instead of a complete process. Multiple customers can get services at the same time. In general, the servlet process is only uninstalled when the Web Server is uninstalled.

Servlet lifecycle:

Load the servlet. This operation is generally dynamically performed. However, Server usually provides an option to force load and initialize a specific servlet when Server starts.

SERVER Create an instance of a servlet

Server call servlet's init () method

A client's request arrives in Server

Server creates a request object

Server creates a response object

Server activates the service () method of servlet, transfer request and response object as parameters

The service () method obtains information about the information on request objects, processing requests, accessing other resources, and obtains information.

The service () method uses the method of responding to the response back to Server, and finally reaches the client. The service () method may activate other methods to process requests, such as doget () or dopost () or new methods developed by the programmer for more client requests, Server creates new requests and responding objects, still activation this servlet The service () method, passes the two objects as a parameter to it. Such cycles are repeated, but no need to call the init () method again. General servlets only initialize once, when Server does not need servlet (usually when Server is closed), Server calls the servlet's Destroy () method.

In the United States, EJB Servlet JSP is almost developing standards for e-commerce. Original ASP is also very promising, but Microsoft may focus on the lawsuits and WIN2000, so e-commerce has developed too little. PHP does not hope because of its model and some natural defects. In the United States, there are very few commercial sites with PHP.

转载请注明原文地址:https://www.9cbs.com/read-92072.html

New Post(0)