1. servlet and JSP Overview

Source: Internet
Author: User
Tags microsoft iis

1.1 Java Servlet and Its Features

Servlet is the answer of Java technology to CGI programming. ServletProgramRun 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 programCodeIt is repeatedly loaded n times in the memory. For servlet, the request is processed by n threads and only one servlet-class 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 ).
1.2 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 to the online store </title> <Body>
<H1> welcome <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>

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.

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.