The servlet servlet is a Java-written server-side program that has nothing to do with protocols and platforms. The servlet runs in the java-enabled Web server. The Java servlet can dynamically extend the capabilities of the server and provide Web services in Request-response mode.
The first
to support servlet technology is the JavaSoft Java Web Server. Since then, some of the other java-based Web servers are starting to support the standard servlet APIs. The main function of the servlet is to interactively browse and modify data to generate dynamic Web content. This process is:
client sends request to server side;
The
server sends request information to the servlet
The
servlet generates response content and passes it to the server. Response content is dynamically generated, usually depending on the client's request
The
server returns the response to the client
The
servlet looks like a normal Java program. The servlet imports specific packages that belong to the Java Servlet API. Because it is an object byte code that can be dynamically loaded from the network, it can be said that the servlet is like an applet to the client, but because the servlet runs in the server, they do not need a graphical user interface. In this sense, the servlet is also called faceless Object.
Advantages of
JAVA servlet:
The
servlet can interact with other resources (files, databases, applets, Java applications, and so on) to generate the response content that is returned to the client. If necessary, you can also save the information in the request-response process.
with a servlet, the server can fully authorize access to local resources (such as databases), and the servlet itself will control the number and nature of access for external users
Servlet can be client programs for other services, for example, they can be used in distributed application systems, can be activated from a local hard disk, or from a remote hard drive through the network.
The
servlet can be linked (chain). A servlet can invoke another or a series of servlet, that is, its client.
uses the servlet tag technology to dynamically invoke the servlet in an HTML page.
The
Servlet API has nothing to do with protocols. It does not have any assumptions about the protocol that passes it.
Like all Java programs, the servlet has all the advantages of an object-oriented Java language
The
servlet provides all the benefits of Java applications-portable, robust, and easy to develop. Using the tag technology of the servlet, the servlet can generate dynamic content embedded in static HTML pages.
a servlet is activated by the first request sent by the client, and then it will continue to run in the background, waiting for a later request. Each request will generate a new thread, not a complete process. Multiple customers can get a service at the same time in the same process. In general, the servlet process is unloaded only when the Web server is unloaded.
servlet Lifecycle:
Mount Servlet. This operation is generally performed dynamically. However, the server typically provides an administrative option to force the loading and initialization of a particular servlet when the server starts.
server creates an instance of a servlet
Server invokes the Init () method of the servlet
a client request arrives at the server
server creates a Request object
server creates a response object
Server activates the service () method of the servlet, passing requests and response objects as parameters
The
Service () method obtains information about the requested object, processes the request, accesses other resources, and obtains the required information
The
Service () method uses the method of the response object to return the response to the server and eventually to the client. The service () method may activate other methods to handle requests, such as doget () or dopost () or new methods developed by the programmer themselves
For more client requests, Server creates a new request and response object and still activates the service () method of the servlet, passing the two objects as parameters to it. Repeat the above loop, but do not need to invoke the Init () method again. The normal servlet is initialized only once, and server invokes the Destroy () method of the servlet when the server no longer needs a servlet (typically when the server shuts down).
in the United States, ejb+servlet+jsp almost become the development standard of E-commerce. ASP is also very promising, but Microsoft recently may focus on litigation and Win2000, so e-commerce development too little. PHP is hopeless because of its pattern and some innate flaws. In the United States, there are few commercial sites with PHP.
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.