OCI JUNE ISSUE
4500 S. Lakeshore Drive, Suite 359, Tempe, AZ 85282 Office: 480-752-0042 1-888-962-4624
Java Technical Insight of the Month - What is a Servlet?
OCI Education Center - Open Enrollment
Java Technical Insight of the Month
What is a Servlet?
By Eric Burke, Senior Software Engineer, Object Computing, Inc.
The typical definition says that a Servlet is a Java class that extends the functionality of a web server, offering an alternative to CGI scripts. Specifically, the javax.servlet and javax.servlet.http packages make up a standard extension to the Java platform, which allows developers to create Servlets. Servlets are usually used for the following tasks: Processing HTML Forms; Interacting with databases; and Dynamically generating HTML.
Ultimately, Servlets allow you to replace static web pages with dynamic web applications.
Advantages of Servlets:
Servlets work on every major web server. You also have the option of running Servlets in a standalone "Servlet Engine", such as Live Software's JRun. Since Servlets are written in Java, they do not have to be re-compiled to run on different web servers.
Contrary to what you might expect, Servlets are typically much faster than CGI programs, even if those CGI programs are written in C. This is because Servlets are persistent. Once a Servlet is loaded into memory, it can be reused by multiple Java threads. Each client request (from a web browser) is handled in a thread, which is much less expensive than creating an entirely new process as CGI requires.
Ease of Development
Servlets are written in Java, therefore all of the familiar Java APIs are available to developers. This allows easy access to relational databases, distributed computing, and portable file I/O. The Servlet API also includes support for parsing HTTP requests from web browsers.
Servlets, like other Java programs, run inside of a Java Virtual Machine (JVM) on a server machine. Servlets cannot access random memory locations and benefit from Java's garbage collector, which greatly reduces the chances for memory errors. The Servlet API also provides consistent exception handling, logging, initialization, and cleanup mechanisms. All of these features allow developers to create highly reliable web applications.
When to Use Servlets:
Servlets are a good option whenever you wish to add dynamic behavior to a web site. Servlets are faster, easier to develop, and more portable than CGI scripts, so it is hard to argue against them. When client-side portability is critical, Servlets are preferable to Applets. Java Applets require your clients to support Java in the web browser, while Servlets can generate pure HTML, which is portable to any browser. Applets also suffer performance problems because of slow initial download times. When special purpose GUI widgets are required, such as wireframe graphics or expandable trees, an Applet may be the only option. However, much of your business logic can still reside in a Servlet. Since both Applets and Servlets are written using Java, it is easy to communicate between the two using RMI, sockets, or directly using the HTTP protocol.
OCI Education Center - Open Enrollment
Registration is being accepted for the Summer-Fall 1999 schedule. Courses are held weekdays from 8:30 a.m. - 3:30 p.m. at the Mesa Community College Business & Industry Institute. Call 480-752-0042 or email training for more information. Click on hypertext for course descriptions and schedule.
Java Syntax for Non-C Programmers
Developing GUIs using Java
Advanced Java Programming
Java Servlet Programming
Introduction to XML
Analysis and Design
Object Oriented Analysis and Design
Introduction to C++ for Non-C Programmers
Object-Oriented Programming and C++
Object Computing, Inc. is a Sun Authorized Java Center in St. Louis and a Member of the Object Management Group, OMG. OCI specializes in distributed computing using object-oriented and web-enabled technologies and provides Consulting, Education, and Product Development services to clients nation-wide. For more information contact our Tempe office at 480-752-0042 or email info.
The Java News Brief is a monthly newsletter. The purpose and intent of this publication is to advance Java, provide technical value, and to announce available OCI Java services. If you would prefer to not receive this newsletter or would like to subscribe please email JNB and enter SUBSCRIBE or UNSUBSCRIBE within the Subject line.
Copyright (c) 1999. Object Computing, Inc.
All rights reserved.
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Object Computing, Inc. is independent of Sun Microsystems, Inc.
OMG, OBJECT MANAGEMENT GROUP, the OBJECT MANAGEMENT GROUP logo, CORBA, CORBA ACADEMY, THE INFORMATION BROKERAGE, DISTRIBUTED OBJECT COMPUTING, OBJECT REQUEST BROKER, ORB, OMG IDL, IIOP, The CORBA LOGO, CORBA THE GEEK & the CORBA THE GEEK design, UNIFIED MODELING LANGUAGE, and UML are trademarks of Object Management Group, Inc. in the United States.