Deploying a Servlet in TomCat

In this document we walk you through all the steps you must take to deploy the sample Servlet into TomCat 3.2.3 Servlet Container.

The steps involved

  1. Preparation

  2. Deploy the example

  3. Run the example
  4. Setting Up the Environment

Preparation

  1. Copy the provided ExcelCalculator.html, and ExcelCalculatorExample.java files into a local directory that will be the target directory of your deployment. These files are included in your jintegra\examples\servlet-com\ServletToExcelCalculator directory when you download J-Integra®.

  2. Include jintegra.jar, and excel.jar into your CLASSPATH environment variable.

  3. Go to the local directory in which you copied ExcelCalculatorExample.java, and enter the following command to compile it:
    javac ExcelCalculatorExample.java

Deploy the example

This section explains how you can run the ExcelCalculatorExample on Jakarta TomCat 3.2.3. Because this example Servlet is using jintegra.jar and excel.jar, you need to set the CLASSPATH environment variable so that the Tomcat Servlet Container will find the classes it needs. You can either create a batch file that sets the CLASSPATH or you can modify the TomCat's startup.bat to include your CLASSPATH.

Another issue is the authentication library. On an NT machine, you need to be authenticated in order to have access to a COM object. J-Integra® comes with a native library that authenticates you automatically. The native library is located in jintegra/bin. You must add this path to your PATH environment variable. Again, either you can write a batch file to set this one or modify TomCat's startup.bat to do the job. After you have finished compiling the proxy files and the ExcelCalculatorExample.java, you are ready to deploy the Servlet.

  1. Ensure that you have you have installed the J-Integra® license.

  2. Create the deployment directory: Create a directory called ExcelExample in the webapps directory of your TomCat folder. In the ExcelExample directory, create two directories named META-INF and WEB-INF. In the WEB-INF directory create a directory named classes. Now you should have a directory structure that looks like this:

  3. Create the XML descriptor: Here is the sample XML descriptor you can use to deploy this example. Save this file as web.xml in the WEB-INF directory.

    This file is included in your jintegra\examples\servlet-com\ServletToExcelCalculator directory (named web.xml) when you download J-Integra®.

    <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'> 
    <web-app> 
     <display-name>ExcelServlet</display-name>  
    <description>no description</description> 
      <servlet> 
       <servlet-name>ExcelCalculator</servlet-name>    
    <display-name>ExcelCalculator</display-name> 
       <description>no description</description>    
    <servlet-class>ExcelCalculatorExample</servlet-class> 
      </servlet> 
      <servlet-mapping>    
    <servlet-name>ExcelCalculator</servlet-name>     
    <url-pattern>/ExcelCalculatorAlias</url-pattern> 
    </servlet-mapping> 
      <session-config>     
    <session-timeout>30</session-timeout> 
    </session-config> 
    </web-app>

  4. Create a manifest file: Create a file called Manifest.mf (it can be an empty file) and save it in the META-INF directory.

  5. Copy ExcelCalculatorExample.class to WEB-INF/classes.

  6. Copy ExcelCalculator.html to ExcelExample.

  7. If you would like to share the jar files used in this example (jintegra.jar, and excel.jar), follow the instruction on Setting up the environment to run a JSP and/or Servlet file. Otherwise create a lib directory under WEB-INF and copy excel.jar, and jintegra.jar on this directory.

  8. After you finished putting these files on the correct place, your directory structure looks like this:

  9. Now you need to add this new servlet to server.xml.  Go to the conf directory and open server.xml.

  10. Add the following lines at the bottom of server.xml just before

    </ContextManager>

      <Context path="/ExcelExample" 
              docBase="webapps/ExcelExample" 
              crossContext="true" 
              debug="0" 
              reloadable="true" 
              trusted="false" > 
      </Context>

Run the example

  1. Shut down the TomCat Server by entering this command:
    shutdown

  2. Re-start the servlet container by entering this command:
    startup

  3. Open your Web browser and enter http://localhost:8080/ExcelExample/ExcelCalculator.html as the URL

  4. Type in two numbers and click Submit.

Setting Up the Environment

For information on setting up the environment for different platforms, see Setting up the environment to run a JSP and/or Servlet file.