Home Frequently Asked Questions Tomcat

 


 

This page answers common questions related to the Tomcat Servlet/JSP engine.
Please note that the tomcat configuration has changed.
Each student has her or his own tomcat server on Vulcan.

 

Questions

 
 
 
 
 
 
 

 


 

Q: How do I start and stop my Tomcat Servlet Engine?


A: Starting and stopping your Tomcat Servlet Engine is fairly easy. Use the following commmands to start your copy of tomcat:

		   user@vulcan ]$  cd $HOME
		   user@vulcan ]$  cd tomcat/bin
		   user@vulcan ]$  ./startup.sh
		 
If your version of tomcat is configured correctly, you should see the following message:

		   Using CATALINA_BASE: /home/user/tomcat
		   Using CATALINA_HOME: /home/user/tomcat
		   Using CATALINA_TMPDIR: /home/user/tomcat/temp
		   Using JAVA_HOME: /usr/java/j2sdk1.4.0_01
		 
NOTE: Your output should display your username rather than user.

Use the following commands to stop your copy of tomcat:

		   user@vulcan ]$  cd $HOME
		   user@vulcan ]$  cd tomcat/bin
		   user@vulcan ]$  ./shutdown.sh
		 
If your version of tomcat is configured correctly, you should see the following message:

		   Using CATALINA_BASE: /home/user/tomcat
		   Using CATALINA_HOME: /home/user/tomcat
		   Using CATALINA_TMPDIR: /home/user/tomcat/temp
		   Using JAVA_HOME: /usr/java/j2sdk1.4.0_01
		 
NOTE: Your output should display your username rather than user.


Q: Why did my Professor give me these port numbers?
What are they used for?


A: In a default configuration, the Tomcat Servlet Engine requires 2 port numbers to function properly. These port numbers are defined in Tomcat's primary configuration file: server.xml.
If you wish to see where this is configured use the following commands to examine your server.xml file:

		   user@vulcan ]$  cd $HOME
		   user@vulcan ]$  cd tomcat/conf
		   user@vulcan ]$  cat server.xml
		  
The port definitions should match the port numbers given to you by your Professor. If the numbers do not match those provided by your Professor, there is a high probability that your servlet engine will not work.

The port definition in the <Connector> tag has special importance because it is required to reach your applications from a browser.

For example, if the port definition in the <Connector> tag is 15006, as in the example above, and you wanted to view index.html in a web application called pace, you would type the following URL:
http://vulcan.seidenberg.pace.edu:15006/pace/index.html


Q: What version of Tomcat am I using?


A: Tomcat version 5.5.12 and the Java JDK 1.5.0_08

Q: Why can't I see changes to my servlets and JSPs even though I recompiled my code?


A: The Tomcat server loads a servlet's *.class file once when the Tomcat server starts. Although we have configured contexts to reload automatically, we have found that this feature does not work to the satisfaction of developers. Simply stop and start your tomcat instance to reinitialize all servlets in your web applications (contexts).

Q: Where do I put the code or files for my applications?


A: The answer depends on the type of file in question. Each web application has the following standard file structure:

/tomcat
    |
    /webapps
        |
        /pace (web application name)
              |
              /WEB-INF
                   |
                   /classes
                   /lib
        /studentapp (student web app)
              |
              /WEB-INF
                   |
                   /classes
                   /lib


Each of these directories has a special purpose:

 
  • The pace directory (web application directory) contains non-executable public files. Files of the following types belong in your javaserver directory:

 
  • .html
  • .jsp
  • .jpg
  • .gif
   
  • The WEB-INF directory contains non-public application files. None of the files in this directory are publicly accessible. Web applications can be configured with a web.xml file. The web.xml file must be stored in the WEB-INF directory. Remember, if you create new app you must enter its specifics into the web.xml or else your servlet will not load

  • The WEB-INF/classes directory contains any .class files required for your application. If your classes or servlets are in packages, you must create sub-directories to replicate the package structure and make sure the .class files are in the correct directory. Do NOT place .jar files in this directory.

  • The WEB-INF/lib directory contains any .jar files needed for your application. If your application requires an XML parser, your parser.jar file should be placed in this directory.

 

Q: What URL do I use to view my application?


A: Here are some examples of how a student would view different resources in a tomcat directory.

Assume that a student has been assigned the following account: s00-cs000-s00

Assume that the student account is on a machine called: vulcan.seidenberg.pace.edu

Assume that the student uses ports: 15005 and 15006 as in the server.xml example above Assume that the student is using a web application called: pace

Assume also that the student has created the following files in her tomcat directory structure:

file location in tomcatURL to access file
$CATALINA_HOME/webapps/pace/index.html http://vulcan.seidenberg.pace.edu:15006/pace/index.html
$CATALINA_HOME/webapps/pace/hello.jsp http://vulcan.seidenberg.pace.edu:15006/pace/hello.jsp
$CATALINA_HOME/webapps/pace
/WEB-INF/classes/HelloWorldServlet.class
http://vulcan.seidenberg.pace.edu:15006/pace/servlet/HelloWorldServlet

NOTE: $CATALINA_HOME is an environment variable unique to every user on the system.
Type the following to identify the value appropriate for your account:

	  user@vulcan ]$ echo $CATALINA_HOME
	  

Q: Where else can I go to learn more about Tomcat?


A: The main resource for information related to tomcat is: http://jakarta.apache.org/tomcat/index.html




If you have any material (questions or answers) that may be useful here, send them to csis@pace.edu