Technical overview and comparison of JSP and Java Servlet

Source: Internet
Author: User
Tags microsoft iis

Java Servlet and Its 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-effective (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, this feature is often free (or requires a very small investment ).

JSP and Its Features

JavaServer Pages (JSP) is a technology that implements common static HTML and dynamic HTML hybrid encoding. For details about the basic concepts of JSP, see JSP technology introduction.

Most pages generated by CGI programs are still static HTML, and dynamic content only appears in limited parts of the page. However, most CGI technologies and their variants, including Servlet, always generate the entire page through a program. JSP allows us to create these two parts separately. For example, the following is a simple JSP page:

 

      <! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"> <HTML> <HEAD> <TITLE> welcome </TITLE> </HEAD> <BODY> <H1> welcome </H1> <SMALL> welcome, <! -- The username for the first access is "New User" --> <% out. println (Utils. getUserNameFromCookie (request); %> to set account information, click the rest of the <a href = http://www.bkjia.com/article/ "Account-Settings.HTML"> here </A> </SMALL> <P> page .. </BODY> </HTML>

Below is a simple comparison between JSP and other similar or related technologies:

 

Below is a simple comparison between JSP and other similar or related technologies:

JSP vs Active Server Pages (ASP)

Microsoft ASP is a technology similar to JSP. JSP has two advantages over ASP. First, the dynamic part is written in Java, rather than VB Script or other Microsoft languages, which is more powerful and easy to use. Second, JSP applications can be transplanted to other operating systems and non-Microsoft Web servers.

Comparison between JSP and Servlet

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 design experts, at the same time, we also set aside space for Servlet programmers to insert dynamic content.

Compared with Server-Side Include (SSI), JSP

SSI is a widely supported technology that introduces external code in static HTML. JSP provides better support in this regard, because it can generate dynamic content using servlets instead of independent programs. In addition, SSI is actually only used for simple inclusion, rather than for "real" programs that can process form data and access the database.

JSP vs JavaScript

JavaScript can dynamically generate HTML on the client. Although JavaScript is useful, it can only process dynamic information based on the client environment. In addition to cookies, HTTP status and form submission data are unavailable for JavaScript. In addition, because it is running on the client, JavaScript cannot access server resources, such as database and directory information.
 

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.