Deploy Web Application on Tomcat 3.3a

by Jeff Hunter, Sr. Database Administrator


server.xml file

It is not recommend adding the new context to the server.xml file. Instead, the ContextXmlReader will read all context definitions (you can customize the "base" filename).
The default is $TOMCAT_HOME/conf/apps-[name].xml

See:

$TOMCAT_HOME/conf/apps-examples.xml
- and -
$TOMCAT_HOME/conf/apps-admin.xml


User Realm File

cd $TOMCAT/conf/users
cp example-users.xml WebDBA-users.xml
DO NOT edit the file WebDBA-users.xml


Create Web Application Directories

cd $TOMCAT_HOME/webapps
mkdir WebDBA
mkdir WebDBA/html
mkdir WebDBA/images
mkdir WebDBA/lib
mkdir WebDBA/WEB-INF
mkdir WebDBA/WEB-INF/classes
mkdir WebDBA/WEB-INF/lib


Create the Deployment Descriptor File


Update the Apache Jserv Configuration File


Testing the New Web Application Setup


Passing Parameters to Servlets

If you are passing parameters to your servlet through the web.xml file and the getInitParameter() method, you will need to keep the following in mind:

  1. Try to use the init() method to capture your parameters while using the getInitParameter() method.

  2. The getInitParameter() method takes the name of the parameter as a String and returns the value as a String.

  3. If you need to return the parameter value as an Integer, use the following:
    int count;
    public void init() throws ServletException {
      String initial = getInitParameter("Parameter Name");
      try {
        count = Integer.parseInt(initial);
      } catch (NumberFormatException e) {
        count = 0;
      }
    }

  4. After making changes to the web.xml file, you will need to restart Tomcat and Apache.

  5. IMPORTANT: You will need to refer to the servlet using the registered name. If not, the parameter will not be passed and the getInitParameter() method will return null.


Understanding URLs with Web Applications

In the previous example, we created an example servlet called "HelloServlet", registered it as "Hi" and mapped it to the root of the web application. In this case, we can access the "Hi" application using either of the URLs:
http://<machine_name>/WebDBA/Hi
- OR -
http://<machine_name>/WebDBA/servlet/Hi
NOTE: Parameter passing will ONLY work using the registered name. In the example above, both URLs will work since they use the Hi registered name. The following URL though will not work:
http://<machine_name>/WebDBA/servlet/HelloServlet


Setting the CLASSPATH Variable for webapps (JAR Files)

The CLASSPATH variable set in your environment variable is being used only for compiling and running non-servlet applications. The Tomcat server uses a separate runtime environment that DOES NOT inherent your CLASSPATH variable setting.

Classes that are used in one particular web application should be placed in that web application's WEB-INF/classes or in a jar in the WEB-INF/lib as defined by the Servlet 2.2 specification. If you want to give the classes wider scope by putting them in the Common Classloader or Apps Classloader, or want them to be part of the Server Classloader, use one of the following two methods to have those classes included in that classloader:

  1. If the classes are in a jar file, place the jar file in the directory that corresponds to the chosen classloader. If the classes exist as class files, create a classes under the corresponding directory if it doesn't already exist. Then add the class files into the appropriate package directory under the classes directory.

  2. If the chosen classloader is the Common Classloader or Apps classloader you include a directory or jar these classloaders by listing them a System property. For the Common Classloader, include the directory or jar file in a System property named org.apache.tomcat.common.classpath. For the Apps classloader, use a System property named org.apache.tomcat.apps.classpath.

You also have the option of setting the CLASSPATH variable for the Tomcat runtime environment in the $TOMCAT_HOME/bin/tomcat.sh script. There is a section called:

## -------------------- Prepare CLASSPATH --------------------



Last modified on: Saturday, 18-Sep-2010 18:14:00 EDT
Page Count: 10495