SP servlet Basics Getting Started learning chapter I, servlet and JSP Overview __jsp

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

1.1 Java Servlet and its features:

The servlet is a Java technology answer to CGI programming. Servlet programs run on the server side and dynamically generate Web pages. 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 (and, more importantly, servlet programmers are earning more:-) than Perl programmers:


1.1 Java servlet and its features

The servlet is a Java technology answer to CGI programming. Servlet programs run on the server side and dynamically generate Web pages. 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 (and, more importantly, servlet programmers are earning more:-) than Perl programmers:


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 has more options than CGI, such as buffering previous calculations, keeping database connections active, and so on.

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.

"Powerful"

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 i-planet 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).
  

1.2 JSP and its characteristics

JavaServer Pages (JSP) is a common static HTML and Dynamic HTML hybrid coding technology, for the description of JSP basic concepts See "JSP technology Introduction."

Many of the pages generated by CGI programs remain static HTML, and dynamic content appears only in a limited number of pages. But most CGI technologies and variants, including the servlet, always generate the entire page through the program. JSP allows us to create these two parts separately. For example, here is a simple JSP page:


! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en"

Welcome to the online store

Welcome


Welcome,
!--first-time user named "New user"-->
<% out.println (Request) (Utils.getusernamefromcookie); %>
To set account information, please click
here


The rest of the page ...


Here is a simple comparison of JSP and other similar or related technologies:

JSP compared to active Server Pages (ASP)

Microsoft's ASP is a technology similar to JSP. There are two advantages to JSP compared with ASP. First, dynamic parts are written in Java, not VB script or other Microsoft languages, and are more powerful and easier to use. Second, JSP applications can be ported to other operating systems and to non-Microsoft Web servers.


JSP compared to the pure servlet

JSP does not add any functionality that cannot be implemented by the servlet in nature. 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 a page design expert, while leaving room for the servlet programmer to insert dynamic content.


JSP and server-side contains (Server-side Include,ssi) compared

SSI is a widely supported technique for introducing external code into static HTML. JSP is more sophisticated in this regard because it can generate dynamic content with a servlet rather than a stand-alone program. In addition, SSI is actually used only for simple inclusion, not for "real" programs that can process form data and Access databases.

JSP is compared with JavaScript

JavaScript can dynamically generate HTML on the client side. Although JavaScript is useful, it can only handle dynamic information that is based on the client environment. In addition to cookies, HTTP status and form submission data are not available for JavaScript. In addition, JavaScript cannot access server-side resources, such as databases, directory information, and so on, because it is running on the client.


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.