Data Centers

Intro to JavaServer Pages: Get your machines ready for JSP

Find out what you need to have in order to use JSP on your machines.

By John Zukowski
(2/8/00)

You'll need a Java 2 Software Development Kit (JSDK), previously known as a Java Development Kit (JDK), and a JavaServer Web Development Kit (JSWDK), Tomcat, or other Web server that supports JSP. Sun offers the JSDK and JSWDK free for the Windows, Solaris, and Linux platforms.

If you want to use JSP with your present Web server, and the server itself doesn't support JSP and Java servlets, try Allaire's Jrun, which acts as a Web server add-on for Netscape's Enterprise and FastTrack Servers, Microsoft's Internet Information Server (IIS) and Personal Web Server (PWS), Apache, and other servers. You can also use the Java version of the Apache Web server, included in the latest JSWDK.

Downloading and Installing What You Need
Currently at release 1.2.2-001, the JSDK downloadable version comes as an installable archive. The approximately 20MB download provides a complete Java development environment, letting you create any Java-based solutions that utilize the core, standard APIs. However, the only thing your Web server needs to work with JSP is access to the Java compiler. To tell the Web server the location of the compiler, set the JAVA_HOME environment variable to the JSDK installation directory. If you've installed on Windows and have accepted the default directory, add the line set JAVA_HOME=C:\1.2.2 to your autoexec.bat file and restart.

After installing the JSDK, download and install either the JSWDK or a beta release of Tomcat, the Java-based Apache Web server. The specifics of where you place this is really irrelevant, as long as you can find it again. Normally, it is just placed in a top-level directory, as this lets you replace the JSWDK or JSDK version without requiring you to move the other. After you've installed this file, you're ready for JSP development.

Once you've installed the JSWDK properly, run the startserver script to start up the Web server to listen on port 8080 by default. To see if you've installed the tool correctly after starting the server, load up one of the sample JSP files (http://localhost:8080/examples/jsp/). If you are able to successfully run one of the sample, file, you know you've set up the software properly. If instead you see an error message in the console window used to start the server, then you need to fix it. The most frequently occurring problem is an unset (or incorrectly set) JAVA_HOME environment variable. To see the current environment settings, type set at the DOS prompt.

Getting Started
Before explaining JSP syntax, create a quick Web page that displays the current date and time and save it as sample.jsp:

<html>
<head>
<title>First Page</title>
</head>
<body>
<H3>Today is:
<%= new java.util.Date() %>
</H3>
</body>
</html>
.

Place this file and all your HTML and JSP pages in a Web pages directory under your JSWDK installation directory. You can load this page at http://localhost:8080/sample.jsp. After the Web server translates the JSP to a Java servlet the first time the page is visited, you'll see the current date and time.

Now that you've downloaded, installed, and configured the development environment, you're set to understand JSP syntax and create your own JSP-based solutions.

John Zukowski is a software guru and director of education at jGuru.com. In addition, John is the author of several Java books and numerous Java-related technical articles.

Editor's Picks

Free Newsletters, In your Inbox