CS Lab Deploy Servlet/JSP Programs to the Tomcat Server | CS | SIU

Southern Illinois University



College of Science

CS Lab Deploy Servlet/JSP Programs to the Tomcat Server

Quick Reference Guide

The Department of Computer Science lab computers have been set up to deploy servlets and JSP to our tomcat server.  This documentation will provide instructions on how to utilize our lab environment for deploying servlets and JSP to our tomcat server.

A more complete documentation is available for off-campus and on-campus computer science labs.

Please note, tomcat 8 (our tomcat deployment server) only supports code compiled with version java 1.7.+.  We recommend end-users download the template to pc00.cs.siu.edu or pc01.cs.siu.edu over ssh and follow the deployment guide to avoid version mismatch errors occurring when you attempt to deploy your template.

1. Please use pc00.cs.siu.edu or pc01.cs.siu.edu over ssh.  Windows users can utilize putty to establish an ssh connection.

2. Download the Tomcat sample servlet deployment  or sample jsp deployment zip archive.

$ wget http://www.cs.siu.edu/download/tomcat/sample-deploy-servlet.zip

3. Unzip the sample deployment archive to any location on your computer.  (You will need to remember this location when you deploy with ant later.)*

$ unzip sample-deploy-servlet.zip

Contents of sample-deploy-servlet:


4. Inside the directory "sample-deploy-servlet" or "sample-deploy-jsp" rename "your_login_ID" to your name ie: jsmith for John Smith

5. Copy any JSP files you want submitted into "sample-deploy\your_login_ID

6. Copy all the servlet ".java" files to sample-deploy\your_login_ID\WEB-INF\classes" directory

Please note when you later execute the ant build command .java files will be compiled to .class servlets with : javac *.java inside of this directory.

7. The sample deployment comes with a valid sample web.xml, which should work for testing your deployment environment.

You'll need to modify the "web.xml" file for different servlets classes.  The file is located at sample-deploy\your_login_ID\WEB-INF.  You'll need to change the name of servlet-class to reflect your java class in the sample code below:

    <!-- Tomcat internal naming convention -->
    <!-- servlet-class is a reference to the HelloWorld.java class -->
    <!-- Tomcat internal naming convention -->
    <!-- Must match above servlet-name -->
    <!-- http://web.cs.siu.edu:8080/your-login-id/HelloWorld-->

In the example above <servlet-class>HelloWorld</servlet-class> needs
to correspond to your HelloWorld.java class file that you deployed.

The field <url-pattern>/HelloWorld</url-pattern> reflects the
location that your servlet will be available on the Tomcat server.

After deploying, this example will be available at:

Note, be sure to change your_login_ID to your own pseudonym.

Additionally reference, the complete web.xml code example file provided by the  tomcat documentation.

8. Copy the newly created "web.xml" file to the "sample-deploy\your_login_ID\WEB-INF" directory or leave the existing one in place for testing compilation of your code into a JAR file.

9. After completing all the steps above, you will have the following directory and file structure :
"sample-deploy\your_login_ID\all_my_ jsp_files

10. Open a dos command prompt or terminal under linux and cd to your sample-deploy-servlet or sample-deploy-jsp directory.

11. To compile your servlet/jsp into a .war file, run command:

ant -buildfile build.xml -Dwebapp=your_login_ID compile

When it is finished, it will tell you whether it is successful or not.

12. To deploy your servlet to the departmental Tomcat server (http://web.cs.siu.edu:8080), run command:

ant -buildfile build.xml -Dwebapp=your_login_ID deploy

You will see it is running the deployment. When it is finished, it will tell you whether it is successful or not.

13. Run your deployed program in your favorite web browser by typing the following url:


For example:

Servlet: http://web.cs.siu.edu:8080/mbarkdoll/HelloWorld
JSP: http://web.cs.siu.edu:8080/mbarkdoll/HelloWorld.jsp

14. Please note, if you compiled and deployed the sample project and plan to modify the same sample deployment project, then it is recommended that you delete the sample project files that we were created.  This will need to be done prior to compiling and deploying the new project to the server.

ie:  These two files inside the servlet sample.



and directory


15.  Additional Resources:

Sample JSP web.xml file:

    <!-- Tomcat internal naming convention -->
    <!-- Servlet Class can be defined many ways -->
    <!-- <servlet-class>org.apache.jsp.HelloWorld_jsp</servlet-class> -->
    <!-- <servlet-class>org.apache.jsp.HelloWorld</servlet-class>
    <!-- Tomcat internal naming convention-->
    <!-- Must match above servlet-name-->


The above example will archive your HelloWorld.jsp file located at
"sample-deploy\your_login_ID" into the .WAR file when compiled.

The .WAR file is used to deploy your application to the Tomcat server.
The <servlet-class>org.apache.jsp.HellWorld_jsp</servlet-class> or more
simply <servlet-class>HelloWorld</servlet-class> in the web.xml
file reflects the directory structure to your .jsp file inside your .WAR archive.

This can be examined after running the ant compile command by exploring
the directory created at "sample-deploy-jsp\your_login_ID\build"

When developing your own application it is possible the directory structure
will change and require that you modify your web.xml file to accommodate
this directory structure appropriately.