Java Servlet Programming and application (i)

Source: Internet
Author: User
Tags command line comparison connection pooling html form microsoft iis

I. Overview

A servlet is a platform-and protocol-independent, server-side Java application that generates dynamic Web pages.

A servlet is a server-side Java application located inside a Web server, unlike a traditional Java application that starts from the command line, which is loaded by a Web server that must contain a Java virtual machine that supports the servlet.

Java Servlet comparison with applets:

Similarities and differences:

* They are not standalone applications and do not have the main () method.

* They are not invoked by a user or programmer, but by another application (container).

* They all have a life cycle that contains the init () and Destroy () methods.

The difference:

* Applet has a good graphical interface (AWT), with the browser, running on the client.

* The Servlet does not have a graphical interface to run on the server side.

Comparison of Java Servlet and CGI (Common Gateway Interface):

Compared to traditional CGI and many other CGI-like technologies, the Java servlet is more efficient, easier to use, more powerful, more portable, and less expensive to invest. In the course of future technology development, the servlet may completely replace the CGI.

* Efficient

In traditional CGI, each request starts a new process, and if the CGI program itself is executing for a short time, the overhead of starting the process is likely to exceed the actual execution time. In the servlet, each request is handled by a lightweight Java thread (rather than a heavyweight operating system process).

In traditional CGI, if there are n concurrent requests for the same CGI program, the CGI program's code is repeatedly loaded n times in memory, and for the servlet, the request is n threads, and only one servlet class code is required. In terms of performance tuning, the servlet also has more options than CGI.

* Convenient

The servlet provides a number of utility routines, such as automatically parsing and decoding HTML form data, reading and setting HTTP headers, processing cookies, tracking session state, and so on.

* Strong function

In the servlet, many tasks that are difficult to accomplish with traditional CGI programs can be done easily. For example, a servlet can interact directly with a Web server, whereas a normal CGI program cannot. The servlet can also share data between programs, making it easy to implement features such as database connection pooling.

* Good portability

The servlet is written in Java and the Servlet API has perfect standards. Therefore, the servlet written for iplanet Enterprise server can be ported to Apache, Microsoft IIS, or WebSTAR without any substantial changes. Almost all mainstream servers support the servlet directly or through Plug-ins.

* Save on Investment

Not only are there a lot of inexpensive and even free web servers for personal or small-scale web sites, and for existing servers, if it doesn't support a servlet, adding that part is often free (or requires very little investment).

Comparison of Java Servlet and JSP (JavaServer Pages):

JavaServer Pages (JSP) is a common static HTML and Dynamic HTML hybrid coding technology, JSP does not add any nature can not be implemented in the Servlet function. However, it is more convenient to write static HTML in the JSP without having to use the PRINTLN statement to output each line of HTML code. More importantly, with the separation of content and appearance, the tasks of different natures in page making can be easily separated: for example, HTML design by the page designer, while leaving room for the servlet programmer to insert dynamic content.

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.