Actually, the explanation below was a bit approximative (late Sunday night 
thing).
It's not really "relative".
The formal explanation is given in the Servlet Specification, but it's more 
like this :

a) Tomcat uses the first path component of the URL, to map a request to a web 
application.
(in your case e.g. "/testvsb").
b) assuming that happened, it then strips this first component from the path, and uses the rest of the path to map the request to a servlet within the application, using the <url-mapping> elements for ditto (and the longest match wins).

If (a) did not find a matching webapp, then Tomcat maps the request to the default application (the one living under /webapps/ROOT/), does not subtract anything from the URL path, and uses the "rest" of the URL path to map the request to a servlet withing the default application, using the <url-mapping> elements for this.

In your case, it means that you should not have to change the <url-mapping> elements in the web.xml, because by the time these mappings are considered, the mapping to the webapp has already taken place, and the first path component has already been removed if needed be.

But you'd better go read how they really say this precisely in the Servlet Spec.



Tod Olson wrote:
Aha, that fixes it.

Thanks for that explanation, I had completely missed that about the url-pattern 
being relative to the webapp.  I clearly need to un-confuse myself about 
servlet-mapping.

Thank you!

-Tod

On Sep 18, 2011, at 2:19 PM, André Warnier wrote:

Hi.

Change the <url-pattern> of your test application, to be exactly the same as the <url-pattern> of the production application.

And invoke it as "http://yourhost.cpy.com/testvsb/";, followed by the same "rest of URL" as what you use for the main application.

Brief explanation : the <url-pattern> is *relative* to the "webapp name". The "webapp name" is the name of your application's directory (in other words, the name of the first directory level under (tomcat_dir)/webapps/).

.. Except one special case : the "default application" lives under the path (tomcat_dir)/webapps/ROOT/ (in capitals), but its "webapp name" is "/".

If the above does not work, then show us how the directory structure under (tomcat_dir)/webapps/ looks like, and which URL you use to access the production application.



Tod Olson wrote:
I would like to run two versions of the same servlet (same servlet-class, but 
with different WAR filename, servlet-name and url-pattern) under a single 
instance of Tomcat 6.0.33.  Basically, the aim  is to run both test and 
production versions of the servlet under the same instance.  Better to run them 
under separate instances, but getting a suitable second instance is proving 
difficult.  I thought that the same servlet-class would be fine as long as the 
servlet-name and url-pattern were different, but does not seem to be enough.

The problem I encounter is that while the production version is deployed by Tomcat just fine, the test version is not loaded. The test version is unbundled in web apps directory and there is a deployment message in the catalina log, but when I point a web browser to the servlet, the result is just HTTP 404 error: "The requested resource (/testvsb/) is not available."
I've been unable to find any kind of useful debugging clues in the catalina 
logs, like a servlet deployment or invocation error, but my knowledge of Tomcat 
is meagre.

The web.xml files for the two servlets are included below, in case they are of 
interest. The init-param sections are the same because I'm still testing out 
the two-servlets-in-one-tomcat concept on my laptop.

Any ideas or advice on how to proceed would be appreciated.

-Tod


Tod Olson <t...@uchicago.edu>
Systems Librarian University of Chicago Library


browse.war
browse/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>

  <servlet>
    <servlet-name>Browse</servlet-name>
        <servlet-class>edu.ncsu.lib.browse.Browse</servlet-class>
        <init-param>
        <param-name>vsiUrl</param-name>
        
<param-value>http://localhost/~tod/virtualshelfindex/handler/</param-value>
        <!-- <param-value>http://your.url.here/virtualshelfindex/</param-value> 
-->
        <!-- 
<param-value>http://webdev.lib.ncsu.edu/virtualshelfindex/</param-value>  -->
        </init-param>
    <init-param>
      <param-name>libraryName</param-name>
      <param-value>The University of Chicago Library</param-value>
    </init-param>
    <init-param>
      <param-name>libraryShortName</param-name>
      <param-value>UChicago</param-value>
    </init-param>
    <init-param>
      <param-name>catalogBaseUrl</param-name>
      <param-value>http://notus.lib.uchicago.edu/staging/</param-value>
    </init-param>

  </servlet>

 <servlet-mapping>
   <servlet-name>Browse</servlet-name>
   <url-pattern>/browse/*</url-pattern>
 </servlet-mapping>

 <session-config>
   <session-timeout>
           30
       </session-timeout>
 </session-config>
 <welcome-file-list>
   <welcome-file>
           browse
       </welcome-file>
 </welcome-file-list>
<error-page>
        <exception-type>
                java.lang.Exception
        </exception-type>
        <location>
                /jsp/error.jsp
        </location>
 </error-page>
</web-app>


testvsb.war:
testvsb/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>

  <servlet>
    <servlet-name>TestVSB</servlet-name>
        <servlet-class>edu.ncsu.lib.browse.Browse</servlet-class>
        <init-param>
        <param-name>vsiUrl</param-name>
        
<param-value>http://localhost/~tod/virtualshelfindex/handler/</param-value>
        <!-- <param-value>http://your.url.here/virtualshelfindex/</param-value> 
-->
        <!-- 
<param-value>http://webdev.lib.ncsu.edu/virtualshelfindex/</param-value>  -->
        </init-param>
    <init-param>
      <param-name>libraryName</param-name>
      <param-value>The University of Chicago Library</param-value>
    </init-param>
    <init-param>
      <param-name>libraryShortName</param-name>
      <param-value>UChicago</param-value>
    </init-param>
    <init-param>
      <param-name>catalogBaseUrl</param-name>
      <param-value>http://notus.lib.uchicago.edu/staging/</param-value>
    </init-param>

  </servlet>

 <servlet-mapping>
   <servlet-name>TestVSB</servlet-name>
   <url-pattern>/testvsb/*</url-pattern>
 </servlet-mapping>

 <session-config>
   <session-timeout>
           30
       </session-timeout>
 </session-config>
 <welcome-file-list>
   <welcome-file>
           browse
       </welcome-file>
 </welcome-file-list>
<error-page>
        <exception-type>
                java.lang.Exception
        </exception-type>
        <location>
                /jsp/error.jsp
        </location>
 </error-page>
</web-app>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to