Part 1: Overview of Servlets and JSP
What are the Advantages of Servlets over Traditional CGI?
Java servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and many alternative CGI-like technologies.
(More importantly, servlet developers tend to get paid more than Perl programmers :-).
Here is a breakdown of the advantages of servlets over CGI:
- Efficient.
With traditional CGI, a new process is started for each HTTP request.
If the CGI program does a relatively fast operation, the overhead of starting the process can dominate the execution time.
With servlets, the Java Virtual Machine stays up, and each request is handled by a lightweight Java thread, not a heavyweight operating system process.
Servlets also have more alternatives than do regular CGI programs for optimizations such as caching previous computations, keeping database connections open, and the like.
- Convenient.
Hey, you already know Java. Why learn Perl too?
Besides the convenience of being able to use a familiar language, servlets have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such tasks.
- Powerful.
Java servlets let you easily do several things that are difficult or impossible with regular CGI.
For one thing, servlets can talk directly to the Web server (regular CGI programs can't).
This simplifies operations that need to look up images and other data stored in standard places.
Servlets can also share data among each other, making useful things like database connection pools easy to implement.
They can also maintain information from request to request, simplifying things like session tracking and caching of previous computations.
- Portable.
Servlets are written in Java and follow a well-standardized API.
Consequently, servlets written for, say I-Planet Enterprise Server can run virtually unchanged on Apache, Microsoft IIS, or WebStar.
Servlets are supported directly or via a plugin on almost every major Web server.
- Inexpensive.
There are a number of free or very inexpensive Web servers available that are good for "personal" use or low-volume Web sites.
But with the major exception of Apache, which is free, most commercial-quality Web servers are relatively expensive.
But once you have a Web server, no matter the cost of that server, adding servlet support to it (if it doesn't come preconfigured to support servlets) is usually cheap or even free.
NEXT
This tutorial is now available as a book: Core Servlets and JavaServer Pages by Marty Hall, published by Sun Microsystems Press.
Read all about it at CoreServlets.com
Server-Side Web Applications using Java Servlets versions 2.1/2.2 and JavaServer Pages (JSP) version 1.0: A Tutorial
© 1999 Marty Hall.
All source code freely available for unrestricted use.
Created for work in the Research and Technology Development Center of the Johns Hopkins University Applied Physics Lab, for courses in the Johns Hopkins Part-Time MS Program in Computer Science, and for various industry seminars and on-site Java short courses.
Please note that this is a first draft of the tutorial, so please send corrections, comments, and suggestions to me at hall@apl.jhu.edu.
Republished with permission from the author. Click here to visit the original version
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|