HomeJava & J2EE Page 3 - Slapping Together A JSP Development Environment
One Tomcat, Standing Alone - Java
Deploying a JSP development environment on your workstation cantest even the strongest of wills, since it requires the peacefulco-existence and cooperation of a number of complex software packages. Thistutorial guides you through the process of getting Apache, JServ and Tomcatconfigured, alerts you to some of the problems you're likely to encounter,and briefly discusses Tomcat contexts and JSP-mySQL connections. Coversboth Windows and Linux.
The first thing you need to do is set up the JDK. Double-click the installable file you just downloaded, and let the program install itself into a convenient location on your hard drive. I'll assume you've installed it to C:\JDK\
Next, go ahead and install Apache - the default installation location of C:\PROGRAM FILES\APACHE GROUP\APACHE\ is fine - and modify the configuration file "httpd.conf" in case you need to customize its operation. You should test that the server is running by starting it up and pointing your browser to http://localhost/ - if you see an Apache test page, that means your server is up and running. You'll also see an MS-DOS window which displays a status message like this:
C:\>APACHE
Apache/1.3.14 (Win32) running...
Third step: install the Tomcat Web server. Now, Tomcat
comes as a single compressed file, which contains both Linux and Windows versions. You don't need to run an installation program; just unzip it to a convenient location and you're done. I used C:\TOMCAT\ as the location for my Tomcat installation.
At this point, it's time to see if the Tomcat server is working (Tomcat works independently of Apache as well). Pop open an MS-DOS window, and set up a few of the environment variables Tomcat needs to function correctly.
Obviously, you need to replace the locations above with
the actual file paths on your system.
Once that's done, change to the Tomcat BIN\ directory and start Tomcat.
C:\TOMCAT\BIN>TOMCAT START
If all went well, you should see something like this:
Including all jars in C:\TOMCAT\LIB in your CLASSPATH.
Using CLASSPATH:
C:\TOMCAT\CLASSES;C:\TOMCAT\LIB\ANT.JAR;C:\TOMCAT\LIB\JAXP.JAR;C:\TOMCAT\LIB
\SERVLET.JAR;C:\TOMCAT\LIB\PARSER.JAR;C:\TOMCAT\LIB\WEBSER~1.JAR;C:\TOMCAT\L
IB\JASPER.JAR;C:\JDK\LIB\TOOLS.JAR
Starting Tomcat in new window
You should also see a new MS-DOS window with something
like this displayed in it:
2001-01-30 02:47:19 - ContextManager: Adding context Ctx( /examples )
2001-01-30 02:47:19 - ContextManager: Adding context Ctx( /admin )
Starting tomcat. Check logs/tomcat.log for error messages
2001-01-30 02:47:20 - ContextManager: Adding context Ctx( )
2001-01-30 02:47:20 - ContextManager: Adding context Ctx( /test )
2001-01-30 02:47:22 - PoolTcpConnector: Starting HttpConnectionHandler on
8080
2001-01-30 02:47:22 - PoolTcpConnector: Starting Ajp12ConnectionHandler on
8007
This indicates that the Tomcat server is running on port 8080.
If, on the other hand, you got this:
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
Out of environment space
then there's one more thing you need to do. Close the
MS-DOS prompt, move to Windows Explorer, and create a new "MS-DOS Prompt" shortcut (you can copy the one in the Start->Programs menu if you like). Right-click the shortcut, find the Memory tab, and change the "Initial Environment" memory size from "Auto" to the maximum (usually 4096 KB). Save the changes to your shortcut, use it to open up a new MS-DOS window, set the environment variables as described above, and try running Tomcat again. This time, things should work as advertised.
Quick aside: since the variables you set are destroyed each time you exit an MS-DOS session under Windows, I'd recommend that you add them to your C:\AUTOEXEC.BAT startup file so that they are permanently installed in memory. Or you could write a simple batch file which creates and sets the variables in MS-DOS before running Tomcat each time.
In order to test your Tomcat installation, point your browser to http://localhost:8080/ and try browsing through the various JSP examples available on the default page at http://localhost:8080/examples/jsp/
Alternatively, you could create a simple JSP file called "hello.jsp" in the directory C:\TOMCAT\WEBAPPS\EXAMPLES\JSP\, containing the following JSP code:
<html>
<body>
<%
out.println("Waiter, can I have a cup of Java, please?");
%>
</body>
</html>
And now, when you point your browser to
http://localhost:8080/examples/jsp/hello.jsp, you should be presented with a page which looks like this:
<html>
<body>
Waiter, can I have a cup of Java, please?
</body>
</html>
If it works, take a deep breath - you're halfway
there! Next, you need to get Apache talking with Tomcat, so that you don't need to add the :8080 suffix each time you want to execute a JSP document.