Java Servlet and JSP tutorial (1)
1 Overview
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.
; Convenient
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? Negative loss? Some mainstream servers support Servlet 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">
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.