Java Servlet and Applet comparison

Source: Internet
Author: User

Java Servlet and Applet are similar:

◆ They are not independent applications and do not have the main () method.

◆ They are not called by users or programmers, but by another application (container.

◆ They all have a life cycle, including the init () and destroy () methods.

Java Servlet differs from Applet:

◆ The Applet has a good graphical interface (AWT) and runs on the client together with the browser.

◆ Servlet does not have a graphical interface and runs on the server.

Comparison between Java Servlet and CGI (Common Gateway Interface:

Compared with traditional CGI and many other CGI-like technologies, Java Servlet is more efficient, easier to use, more powerful, more portable, and more investment-saving. In the future technological development, Servlet may completely replace CGI.

◆ 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.

◆ 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 IPlanet 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

Java Servlet and Applet not only have many low-cost or even free Web servers for personal or small-scale websites, but also if the existing server does not support Servlet, this feature is often free (or requires a very small investment ).

Comparison between Java Servlet and JSP (assumerver Pages:

JavaServer Pages (JSP) is a technology that implements the hybrid coding of common static HTML and dynamic HTML. JSP does not add any functions that cannot be implemented by Servlet in essence. However, it is more convenient to compile static HTML in JSP, and you do not need to use the println statement to output each line of HTML code. More importantly, with the separation of content and appearance, different types of tasks in page creation can be easily separated: for example, HTML design is performed by page designers, at the same time, we also set aside space for Servlet programmers to insert dynamic content.

Java Servlet API 2.2

Java Servlet API 2.2 consists of two Java packages: javax. servlet and javax. servlet. http (also including javax. servlet. jsp package, not discussed in this article ).

The javax. servlet package provides the Servlet interface necessary to control the Servlet lifecycle, which must be implemented during Servlet compilation.

The javax. servlet. http package provides an abstract class and a general tool class derived from the Servlet interface for processing HTTP requests. All Servlet objects must implement the Servlet interface. In most cases, it is used as the javax that has implemented the Servlet interface. servlet. genericServlet and javax. servlet. http. httpServlet subclasses of these two abstract classes indirectly implement the Servlet interface.

  1. How to listen to Servlet containers
  2. Introduction to Servlet and JavaServer Page
  3. Introduction to Http Servlet Request objects
  4. Servlet API strength
  5. What is the role of ServletContext?

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.