Analysis of Servlet definition and Principle

Source: Internet
Author: User
Tags microsoft iis

What is Servlet defined? What is the relationship between Servlet and Java? Servlet is a Server program written in Java. It has nothing to do with the Protocol and platform. Servlet runs in Java-enabled Web Server. Java Servlet can dynamically expand Server capabilities and provide Web Services in the request-response mode.

The earliest Java Web Server that supports Servlet technology is JavaSoft. Later, some other Java-based Web servers began to support standard Servlet APIs.

1. Servlet-defined Servlet features

Servlet is the answer of Java technology to CGI programming. Servlet programs run on the server to dynamically generate Web pages. Compared with traditional CGI and many other CGI-like technologies, Java Servlet is more efficient, easier to use, more powerful, and more portable, more cost-saving, more importantly, Servlet programmers earn more income than Perl programmers :-)

◆ Efficient

In traditional CGI, each request starts a new process. If the CGI program runs for a short period of time, the overhead required to start the process may exceed the actual execution time. In Servlet, each request is processed by a lightweight Java thread rather than a heavyweight operating system process ). In traditional CGI, if there are N concurrent requests to the same CGI program, the CGI program code is repeatedly loaded N times in the memory. For Servlet, the request is processed by N threads and only one Servlet code is required. In terms of performance optimization, Servlet also has more options than CGI, such as buffering previous computing results and maintaining database connection activities.

◆ Convenience

Servlet provides a large number of Utility Routines, such as automatically parsing and decoding HTML form data, reading and setting HTTP headers, processing cookies, and tracking session status.

◆ Powerful functions

In Servlet, many tasks that are difficult to accomplish by using traditional CGI programs can be easily completed. For example, a Servlet can directly interact with a Web server, but a common CGI program cannot. Servlet can also share data among various programs, making database connection pools and other functions easy to implement.

◆ Good portability

Servlet is compiled in Java, and the Servlet API has perfect standards. Therefore, servlets written for the I-Planet Enterprise Server can be transplanted to Apache, Microsoft IIS, or WebStar without any material changes. Almost all mainstream servers support servlets directly or through plug-ins.

◆ Save investment

Not only are there many low-cost or even free Web servers available for personal or small-scale websites, but if the existing server does not support Servlet, these features are often free or require a very small investment ).

Ii. Servlet-defined main functions of Servlet

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

◆ The client sends a request to the server;

◆ The server sends the request information to the Servlet

◆ Servlet generates the response content and sends it to the Server. The dynamic generation of response content usually depends on the client request

◆ The server returns the response to the client

Servlet looks like a common Java program. Servlet imports a specific Java Servlet API package. Because it is an object bytecode that can be dynamically loaded from the network, it can be said that the Servlet is the same as the Applet to the Client, but because the Servlet runs on the Server, they do not need a graphical user interface. From this perspective, Servlet is also called a Faceless Object.

Iii. Advantages of JAVA Servlet

Servlet can interact with other resources (files, databases, applets, Java applications, etc.) to generate the response content returned to the client. If necessary, you can also save the information in the request-response process.

Using Servlet, the server can fully authorize access to local resources (such as databases), and the Servlet itself will control the access quantity and access nature of external users.

Servlets can be client programs of other services. For example, they can be used in Distributed Application Systems to activate servlets from local hard disks or from remote hard disks through networks.

Servlet can be linked (chain ). A Servlet can call another Servlet or a series of servlets to become its client.

Using Servlet Tag technology, you can dynamically call servlets on HTML pages.

The Servlet API has nothing to do with the protocol. It does not have any assumptions about the protocols that pass it.

Like all Java programs, Servlet has all the advantages of Object-Oriented Java language

Servlet provides all the advantages of Java applications-portability, stability, and ease of development. Using Servlet Tag technology, 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 continues to run in the background, waiting for future requests. Each request generates a new thread instead of a complete process. Multiple customers can get services in the same process at the same time. Generally, the Servlet process is uninstalled only when the Web Server is uninstalled.

The definition of Servlet is not a good one, so many of them are summarized and summarized. The above is the analysis of the definition of Servlet in this article, hoping to help you.

  1. Automatic jump to error page for JSP Servlet instance
  2. 8-point discussion on optimizing JSP Servlet applications
  3. What are servlets and common Servlet APIs?
  4. At the beginning of JSP Servlet Development
  5. Servlet import event-driven technology in JSP development

Related Article

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.