tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gerry Matte" <Mat...@gov.saanich.bc.ca>
Subject Re: Can't Run Servlet from anywhere but examples
Date Wed, 19 Jul 2000 00:19:34 GMT
Hi Melissa.  It took me the last three days to resolve that particular dilemna so I'll share
it while it's fresh:

You will need to understand the web applications environment as described in the Tomcat application
developer guide located in <TOMCAT-HOME>/doc/appdev/index.html.  I re-read this about
five times before it began to make sense.

The approach that I eventually used is described as the first bullet in section 3.4

I tinkered with server.xml and then undid my changes after some research into the tomcat documentation.
 Stay out of this file.

In the tomcat/conf/tomcat.conf file, I made a single change to implement a new servlet context
called "gmtests":
After "ApJServMount /servlet /root" I inserted a new statement: 
    ApJServMount /gmtests ajpv12://127.0.0.1:8007
This tells apache web server to pass browser requests with /gmtests over to the tomcat servlet
engine to handle.

Then I copied my "gmtests" directory to the tomcat webapps directory so that it was at the
same directory level as examples, test,admin, and root (the standard tomcat servlet contexts)
.

Finally you need to define each servlet within a web.xml file within directory webapps/gmtests/web-inf.
 My file contains the following:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

<web-app>
    <!-- General description of your web application -->
    <!-- ***** The display-name & description causes a JVM Page fault when Tomcat shuts
down.  Run shutdown twice to clear. *****
    <display-name>Saanich demo Servlets and JSP Pages</display-name>
    <description>This is version 1.0 of the test and demo environment for servlets and
JSP pages.  Tested demonstration and benchmark servlets and JSP's are here. It was written
by Gerry Matte(matteg@gov.saanich.bc.ca), who should be contacted for more information.  This
definition is in web.xml within webapps gmtests.  See web.xml.txt for other possible entries
(supplied with the Tomcat 3.1 package).</description>
    -->

    <!-- Context initialization parameters that define shared
         String constants used within your application, which
         can be customized by the system administrator who is
         installing your application.  The values actually
         assigned to these parameters can be retrieved in a
         servlet or JSP page by calling:

             String value =
               getServletContext().getInitParameter("name");

         where "name" matches the <param-name> element of
         one of these initialization parameters.

         You can define any number of context initialization
         parameters, including zero.
    -->
    <context-param>
      <param-name>webmaster</param-name>
      <param-value>matteg@gov.saanich.bc.ca</param-value>
      <description>The EMAIL address of the administrator to whom questions and comments
about this application should be addressed.</description>
    </context-param>

    <!-- Servlet definitions for the servlets that make up
         your web application, including initialization
         parameters.  With Tomcat, you can also send requests
         to servlets not listed here with a request like this:

           http://localhost:8080/{context-path}/servlet/{classname}

         but this usage is not guaranteed to be portable.  It also
         makes relative references to images and other resources
         required by your servlet more complicated, so defining
         all of your servlets (and defining a mapping to them with
         a <servlet-mapping> element) is recommended.

         Servlet initialization parameters can be retrieved in a
         servlet or JSP page by calling:

             String value =
               getServletConfig().getInitParameter("name");

         where "name" matches the <param-name> element of
         one of these initialization parameters.

         You can define any number of servlets, including zero.
    -->
    <servlet>
        <servlet-name>HelloUser</servlet-name>
        <servlet-class>tests.HelloUser</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>SnoopServlet</servlet-name>
        <servlet-class>tests.SnoopServlet</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>SnoopServlet2</servlet-name>
        <servlet-class>tests.SnoopServlet2</servlet-class>
    </servlet>

    <!-- Define mappings that are used by the servlet container to
         translate a particular request URI (context-relative) to a
         particular servlet.  The examples below correspond to the
         servlet descriptions above.  Thus, a request URI like:

           http://localhost:8080/{contextpath}/HelloUser

         will be mapped to the "HelloUser" servlet, while a request like:

           http://localhost:8080/{contextpath}/saveCustomer.do

         will be mapped to the "controller" servlet.

         You may define any number of servlet mappings, including zero.
         It is also legal to define more than one mapping for the same
         servlet, if you wish to.
    -->
    <servlet-mapping>
    	<servlet-name>HelloUser</servlet-name>
    	<url-pattern>/HelloUser</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    	<servlet-name>SnoopServlet</servlet-name>
    	<url-pattern>/SnoopServlet</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    	<servlet-name>SnoopServlet2</servlet-name>
    	<url-pattern>/SnoopServlet2</url-pattern>
    </servlet-mapping>
</web-app>

===========  Good Luck =======
Gerry Matte


=======================================================
Gerry Matte, IT Manager, Municipality of Saanich
mailto:matteg@gov.saanich.bc.ca    http://www.gov.saanich.bc.ca
Phone (250) 475-5403        Fax: (250) 475-5411


>>> melissa@cendex.com 2000-07-18 16:42:22 >>>
I am trying to run a servlet from an HTML page (HelloWorldExample).  The
only place it seems to work is in the examples directory that came with the
tomcat installation.  I have copied the configuration for the examples
directory server.xml and simply changed the name.  In its new location, it
will not run.  The tomcat-apache.conf file looks correct.

Any ideas?

TIA
Melissa Matthews

Cendex Corp
Phone 703.205.9256
Fax 703.205.2961



Mime
View raw message