Tomcat Setup and Use

This guide describes using Tomcat to make a simple web server.

Setting up a Simple Tomcat Server

For another reference, see: http://hakata.mt.cs.cmu.edu/20-783_2001/Handouts/tools.html

Download Tomcat. Follow the instructions in running.txt. Just set JAVA_HOME and CATALINA_HOME, and run the startup.bat in the bin directory. It will display "INFO: Jk running" when it has started. Then try http://localhost:8080

The web pages are in the webapps/root directory. To make your own pages, make your own index.jsp file. Make sure there is a WEB-INF directory under root. Make additional pages and reference them with a link from the original page. Note that the Tomcat server does not have to be restarted to load a new page.

Tomcat Server using Ant and Eclipse

See the JBoss setup guide for more information about the tools, installation and extraction.

Download and install Ant.
Download and install Eclipse.
Download the tomcatSample.zip. Extract it somewhere such as NetDB/TomcatSample.
Download the Sysdeo Eclipse pugin if you would like to run Tomcat from Eclipse. The plugin options can be turned on under Window-Customize Perspective. Change the Window Preferences-Tomcat and choose Version 4.1.x. Change the Tomcat home to the CATALINA_HOME location.

Make a new Java Project in Eclipse and point it to NetDB/TomcatSample.
Run Window-Show View-Ant in Eclipse. Then right click in the Ant window and add the build.xml build file from the tomcat sample project.
Add the tomcat common/lib/servlet.jar to Eclipse using Window Preferences-Ant-Runtime-Classpath. Also add the Ant Path if it isn't already. Also add the jar to Eclipse using Project Properties- Java Build Path-Libraries.

Add <property file=".ant.properties" /> to the build.xml file under the <project element. Make a ".ant.properties" file in the TomcatSamples root directory and add the line "tomcat.home=d:/netdb/apache group/jakarta-tomcat-4.1.18" or point to whereever your CATALINA_HOME environment variable points.

Double click on the compile build target in the Ant window of Eclipse. Start Tomcat by running bin/Startup.bat or from Eclipse, and then try http://localhost:8080/hello

Simple Tomcat Server with Database

Download and install MySQL and Connector/J. The Tomcat sample already comes with a JDBC driver named mysqldriver.jar, but it is not needed if Connector/J is used.
Copy the mysql-connector-java-3.0.6-stable.jar to the Tomcat common/lib directory or into the lib directory of the project.
Change the DBTest.java source code to:
String dbServer = "jdbc:mysql://localhost/test";
This will attempt to open a database named "test". If the database exists, then a table named "author" is required by the source code. If Tomcat was started from within Eclipse, these errors will display in the console window of Eclipse.

Other Links

See the following link for writing Servlet code. Tomcat Servlets
Hosted by www.Geocities.ws

1