Tutorials : Using Apache Tomcat 4 :
Contents
Introduction
Configure Tomcat
Test the Server
Set Up Your Development Environment
Compile and Test Some Simple Servlets
Establish a Simplified Deployment Method

Test the Server

Testing the server involves two steps:

  1. Verifying that the server can even start.
  2. Checking that you can access your own HTML and JSP pages.

1. Verify That the Server Can Start

Before trying your own servlets or JSP pages, you should make sure that the server is installed and configured properly. For Tomcat, click on install_dir/bin/startup.bat (or execute install_dir/bin/startup.sh on Unix/Linux). Next, enter the URL http://localhost/ in your browser and make sure you get the Tomcat welcome page, not an error message saying that the page cannot be displayed or that the server cannot be found. If you chose not to change the port number to 80 as described above, you will need to use a URL like http://localhost:8080/ that includes the port number.

To halt the server, double click on install_dir/bin/shutdown.bat. I recommend that you make shortcuts to (not copies of) the startup and shutdown scripts and place those shortcuts on the desktop or in your main development directory. If you use an IDE, you'll have to tell it where these scripts are.

2. Try Some Simple HTML and JSP Pages

After you have verified that the server is running, you should make sure that you can install and access simple HTML and JSP pages. This test, if successful, shows two important things. First, successfully accessing an HTML page shows that you understand which directories should hold HTML and JSP files. Second, successfully accessing a new JSP page shows that the Java compiler (not just the Java virtual machine) is configured properly.

Eventually, you will almost certainly want to create and use your own Web applications (see Chapter 4 of More Servlets and JavaServer Pages), but for initial testing I recommend that you use the default Web application. Although Web applications follow a common directory structure, the exact location of the default Web application is server specific. With Tomcat 4 and the default Web application, you put HTML and JSP pages in install_dir/webapps/ROOT or install_dir/webapps/ROOT/SomePath and access them with http://localhost/filename or http://localhost/SomePath/filename. Note that Tomcat creates install_dir/webapps/ROOT when the server is first run. So, you must start the server as described above before trying to access the directory.

For your first tests, I suggest you simply take Hello.html and Hello.jsp and drop them into the appropriate locations. Right click on the links to download these two files to your system. The code for these files, as well as all the code from the book, is available online at http://www.moreservlets.com. That Web site also contains book updates, additions, information on servlet and JSP short courses, and the full text of Core Servlets and JavaServer Pages (in PDF).

If you put the files in the top-level directory of the default Web application (i.e., in install_dir/webapps/ROOT), access them with the URLs http://localhost/Hello.html and http://localhost/Hello.jsp, respectively. If you put them in a subdirectory of install_dir/webapps/ROOT, use the URLs http://localhost/directoryName/Hello.html and http://localhost/directoryName/Hello.jsp, respectively.

If neither the HTML file nor the JSP file works (e.g., you get File Not Found--404--errors), you likely are using the wrong directory for the files. If the HTML file works but the JSP file fails, you probably have incorrectly specified the base JDK directory (e.g., with the JAVA_HOME variable).



Reprinted with permission from Marty Hall. This tutorial is also available at http://www.moreservlets.com/Using-Tomcat-4.html

How to Add Java Applets to Your Site

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.