Hi,

The changes you describe below weren't quite what I meant. I guess
I should have been more explicit.

I suggest:

step 1:
  define your webapp in the $TOMCAT_HOME/conf/server.xml file with a prefix,
like

        <Context path="/mywebapp"
                 docBase="/home/mywebapproot"
                 debug="0"
                 reloadable="true"
                 trusted="false" >
        </Context>

  and in your web.xml, add something like:
    <servlet>
        <servlet-name>
            invoker
        </servlet-name>
        <servlet-class>
            org.apache.tomcat.servlets.InvokerServlet
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>
            invoker
        </servlet-name>
        <url-pattern>
            /myservlets/*
        </url-pattern>
    </servlet-mapping>

This should allow you to run your servlets (ie any class which implements
Servlet, and 
whose .class file is stored under yourwebapproot/WEB-INF/classes) using urls
like
 http://somehost:8080/mywebapp/myservlets/somepkg.someservletclass

If you don't like having all your servlets "appear" to be under one
directory, don't
like having to type in the package name, want servlets to be invoked by
names
which don't match the actual java class name, or want to pass initialisation
params
to servlets, then you have to add individual <servlet> and <servlet-mapping>
tags for 
each servlet instead of setting up an InvokerServlet.

Note that the InvokerServlet is just an ordinary servlet - you could have
written it yourself,
but tomcat nicely provides an implementation. Above, the standard
<servlet-mapping>
feature is used to redirect all urls starting with "myservlets" to an
"ordinary" servlet called
InvokerServlet. The code inside InvokerServlet just fetches the rest of the
URL, and then
calls the java "getClassFor" method, and (provided it succeeced) calls the
class.

step 2:
Change the "path" attribute in the <context> entry from "/mywebapp" to "",
which will get rid
of the "mywebapp" prefix, so that you can run your servlets as
 http://somehost:8080/myservlets/somepkg.someservletclass


Remember that the settings in $TOMCAT_HOME/conf/server.xml are applied to
*all* webapps within
a tomcat instance. I think that by doing redirections at this level, you can
cause really nasty side-effects.
I'm not sure what an InvokerInterceptor actually does, but I think it is too
"high-level" for achieving what
you want to achieve.

Try thinking of a webapp as an application, like microsoft word. Changing
settings in a webapp's web.xml
file is like selecting File|Properties within word to modify setting for the
word application. Changing
settings in $TOMCAT_HOME/conf/server.xml is like changing
operating-system-wide settings.

Regards,

Simon

> -----Original Message-----
> From: Thyagesh [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, December 19, 2000 1:07 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: Need Some help..
> 
> Hi,
>     Thanks Simon for the valuable advice. I got most of it. I still need
> some clarifications:
> 
> I am use:    Tomcat 3.2
>                  WindowsNT4
>                   IIS 4.0.
> 
> Things I did is:
> 1) I Repeated the following lines in server.xml in <tomcat home/conf>
>     for different context-paths
> (i.e. for  http://host/context-path/<servlet name>:     /servlet, /login
> etc)
> 
>     by adding different values of 'prefix' attribute.
> 
> <RequestInterceptor
>             className="org.apache.tomcat.request.InvokerInterceptor"
>             debug="0" prefix="/login/" />
> 
> 2) Defined mappings in web.xml (in webapps/root/.../web.xml) for all
> servlets that are in packages.
> 
>         This seems to work when I requests to Tomcat directly. I wanted to
> know:
> A) whether the above configurations is logically CORRECT.
> 
> -Thanks
> 
> -Thyagesh
> 
> 
> 
> 
> ----- Original Message -----
> From: Kitching Simon <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, December 18, 2000 4:43 PM
> Subject: RE: Need Some help..
> 
> 
> > Hi,
> >
> > I suggest thinking of your mappings in two steps:
> > (a) get the mappings right *within* a context
> > (b) decide what context prefix you want.
> >
> > If you ve a context with a path (ie url prefix) of
> > "mywebapp", then you can set up URLs as you desire
> > *within* that webapp.
> >
> > Configuring the url->servlet mappings (ie what servlet
> > is run when a user requests a particular url) is done
> > by defining <servlet-mapping> tags within the
> > WEB-INF/web.xml file for your webapp. The urls
> > you define like this are all *relative* to the webapp
> > url, eg if you set up a mapping from "/foo" to the
> > java class "mypackage.myclass", then it must be
> > accessed by the user as "http://somehost/webappname/foo".
> >
> > If you have a whole bunch of servlets, and you don't want
> > to enter separate servlet-mapping entries for each one, then
> > you may want to take advantage of the "invoker servlet" which
> > effectively sets up bulk url mappings for you, but doesn't give
> > you such fine control as creating invididual mappings.
> >
> > Deciding whether you want the webapp to have a
> > prefix of "/" (ie be the root webapp) is a separate
> > thing. This is configured with the <context> tag
> > in the $TOMCAT_HOME/conf/server.xml file.
> >
> > WAR files have nothing to do with paths at all; they
> > are just a convenient method of installing the bunch of
> > files making up a webapp.
> >
> >
> > PS: In future, please specify your tomcat VERSION, as
> > answers to questions often depend on which tomcat you
> > are using.
> >
> > Regards,
> >
> > Simon
> >

Reply via email to