Java and the Web

To round off our discussion of Java, especially those aspects of special interest to Oracle developers using Java on the Web, we’ll take a look at servlets, JavaServer Pages, and servlet runners in the following sections.

Java Servlets

A Java servlet is nothing more than a Java program that sits on a web server delivering web content, doing much the same thing that a Perl CGI program might do. In fact, Java servlets are essentially just “Java CGI” programs. The name “servlet” itself is a sort of pun on “applet.” If it weren’t such a tongue-twister, applets might have been called “clientlets” (try saying that after a glass of Chardonnay).

Java servlets are becoming hugely important in the world of Oracle web applications, and in servlets Java has found itself a valuable niche, especially within the realm of the Apache JServ web server covered later in this chapter. Servlets have some advantages over traditional CGI scripting techniques, in particular:

They are highly portable.

Java servlets written on your Windows NT machine can be transferred later to your Solaris or Linux machines without any code changes.

They avoid the areas where Java is weak.

For example, they don’t require the AWT (Abstract Windowing Toolkit).

They benefit from the strengths of the core Java APIs.

These strengths include JDBC, multi-threadability, networking, and so on.

They are remarkably efficient.

Servlets usually remain as object instances in memory until the web server is shut down. If they ...

Get Oracle and Open Source now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.