Servlet and JSP Overview

Source: Internet
Author: User

1.1 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 (the most popular WEB Server platform on the Unix platform), 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 ).
1.2 jsp (preferred for SUN Enterprise applications) and Its Features

Extends erver Pages (jsp (preferred for SUN enterprise-level applications) is a technology that implements common static HTML and dynamic HTML hybrid encoding. jsp (preferred for SUN enterprise-level applications) for basic concepts, see jsp (the first choice for SUN Enterprise Applications) 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 (the preferred choice for SUN Enterprise Applications) allows us to create these two parts separately. For example, the following is a simple jsp (preferred for SUN Enterprise Applications) page:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD> <TITLE> welcome to the online store </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
<A href = "Account-Settings.html"> here </A> </SMALL>
<P>
The rest of the page ..
</BODY> </HTML>



Below is a simple comparison between jsp (the preferred choice for SUN Enterprise applications) and other similar or related technologies:

Jsp (preferred for SUN Enterprise Applications) compared with Active Server Pages (ASP)

Microsoft ASP is a technology similar to jsp (preferred for SUN Enterprise applications. Jsp (the preferred choice for SUN Enterprise Applications) 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 (preferred for SUN Enterprise Applications) applications can be transplanted to other operating systems and non-Microsoft Web servers.


Jsp (preferred for SUN Enterprise Applications) compared with pure Servlet

Jsp (the preferred choice for SUN Enterprise Applications) does not add any functionality that cannot be implemented by Servlet in essence. However, it is more convenient to compile static HTML in jsp (the preferred choice for SUN Enterprise applications), so you do not have to use println statements to output every 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 (preferred for SUN Enterprise applications)

SSI is a widely supported technology that introduces external code in static HTML. Jsp (the preferred choice for SUN Enterprise Applications) is more comprehensive in this regard, because it can generate dynamic content using servlets rather than 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.

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.