You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Arion <ar...@talentinfo.com.hk> on 2000/03/01 03:53:25 UTC

How can I change the servlet path?

Hi!

The default local path for CONTEXT is <CONTEXT docbase>/web-inf/classes,
am I right? How can I override the setting say <CONTEXT
docbase>/servlet?

Thank you

Arion


Context Paths was Re: How can I change the servlet path?

Posted by Shawn McMurdo <sh...@lutris.com>.
This brings up something that we've run into which is the need
for a Context to have multiple paths.
Examples might be accessing the same application via both
http and https or accessing the same applicaiton by two
different names or on two different ports.
Has anyone else encountered this need?
Shawn

"Craig R. McClanahan" wrote:

> Arion wrote:
>
> > Hi!
> >
> > I have read the specification, but I am still confused about some of the
> > points:
> >
> > Is the reason for the servlet URL be <CONTEXT>/servlet/ because servlet is its
> > resource name and we are going to get this resource under this context? Is this
> > necessary meaning that we have no way to change the name?
> >
>
> Technically, the context-relative URI "/servlet" is mapped to a special servlet
> inside Tomcat called the "invoker" servlet.  The invoker looks at the rest of the
> request URI (specifically, the getPathInfo() part) and assumes that this is the
> class name of a servlet class to be looked up on the class path (which includes
> /WEB-INF/classes and /WEB-INF/lib/*.jar) and executed.  In this way, you can
> execute servlets that have not been listed in the web.xml file explicitly.
>
> Tomcat lets you turn on and off the invoker servlet (some people won't want it for
> security reasons), but you cannot change the mapping to "/servlet" without
> changing the Tomcat source code.  The only other way to reference a servlet is via
> a <servlet-mapping> (either to a path or to a filename extension).
>
> Servlets you map with <servlet-mapping> settings have two interesting features:
> * You can specificy initialization parameters for them
>   in the web.xml file.
> * You can use relative paths, even for your servlets,
>   so that you can deploy your app on a completely
>   different context path, and change NOTHING
>   in your application.
>
> An example of the latter case -- let's say you have a JSP page at the
> context-relative path "editCustomer.jsp" which submits a form to a servlet mapped
> to the context-relative path "saveCustomer".  Using relative paths, you can do
> this:
>
>     <form method="post" action="saveCustomer">
>         ...
>     </form>
>
> in your JSP page and the "saveCustomer" relative URI will be resolved correctly,
> no matter what your context path is.
>
> >
> > If I want to use different name, must I specific the name for each servlet
> > using servlet-mapping?
> >
>
> Yes.  It's also possible to create multiple mappings for the same servlet, if you
> want to.
>
> >
> > Thanks
> >
> > Arion
> >
>
> Craig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

--
Shawn McMurdo              mailto:shawn@lutris.com
Lutris Technologies        http://www.lutris.com
Enhydra.Org                http://www.enhydra.org



Re: How can I change the servlet path?

Posted by "Craig R. McClanahan" <cm...@mytownnet.com>.
Arion wrote:

> Hi!
>
> I have read the specification, but I am still confused about some of the
> points:
>
> Is the reason for the servlet URL be <CONTEXT>/servlet/ because servlet is its
> resource name and we are going to get this resource under this context? Is this
> necessary meaning that we have no way to change the name?
>

Technically, the context-relative URI "/servlet" is mapped to a special servlet
inside Tomcat called the "invoker" servlet.  The invoker looks at the rest of the
request URI (specifically, the getPathInfo() part) and assumes that this is the
class name of a servlet class to be looked up on the class path (which includes
/WEB-INF/classes and /WEB-INF/lib/*.jar) and executed.  In this way, you can
execute servlets that have not been listed in the web.xml file explicitly.

Tomcat lets you turn on and off the invoker servlet (some people won't want it for
security reasons), but you cannot change the mapping to "/servlet" without
changing the Tomcat source code.  The only other way to reference a servlet is via
a <servlet-mapping> (either to a path or to a filename extension).

Servlets you map with <servlet-mapping> settings have two interesting features:
* You can specificy initialization parameters for them
  in the web.xml file.
* You can use relative paths, even for your servlets,
  so that you can deploy your app on a completely
  different context path, and change NOTHING
  in your application.

An example of the latter case -- let's say you have a JSP page at the
context-relative path "editCustomer.jsp" which submits a form to a servlet mapped
to the context-relative path "saveCustomer".  Using relative paths, you can do
this:

    <form method="post" action="saveCustomer">
        ...
    </form>

in your JSP page and the "saveCustomer" relative URI will be resolved correctly,
no matter what your context path is.


>
> If I want to use different name, must I specific the name for each servlet
> using servlet-mapping?
>

Yes.  It's also possible to create multiple mappings for the same servlet, if you
want to.

>
> Thanks
>
> Arion
>

Craig



Re: How can I change the servlet path?

Posted by Arion <ar...@talentinfo.com.hk>.
Hi!

I have read the specification, but I am still confused about some of the
points:

Is the reason for the servlet URL be <CONTEXT>/servlet/ because servlet is its
resource name and we are going to get this resource under this context? Is this
necessary meaning that we have no way to change the name?

If I want to use different name, must I specific the name for each servlet
using servlet-mapping?

Thanks

Arion

"Craig R. McClanahan" wrote:

> Arion wrote:
>
> > Hi!
> >
> > The default local path for CONTEXT is <CONTEXT docbase>/web-inf/classes,
> > am I right? How can I override the setting say <CONTEXT
> > docbase>/servlet?
> >
>
> You are confusing the class path for a context (used to locate all Java
> classes referenced by a web application, not just servlet classes) with the
> URL that is mapped to a particular servlet.
>
> The 2.2 servlet specification defines that all classes under
> WEB-INF/classes (and all JAR files under WEB-INF/lib) become part of the
> class path for a particular context.  However, this has nothing to do with
> how you access servlets found in those directories via a URL.
>
> If you use a URL like "/{context-path}/servlet/xxxxx", Tomcat looks for a
> class named "xxxxx" in one of the above two locations, or along the system
> class path if not found there.  It follows the usual Java rules for
> resolving classes that are inside packages.
>
> In addition, you can map a servlet to a specific path to a specific servlet
> using <servlet-mapping> element in the web.xml file.  Again, the class
> itself is located by looking in WEB-INF/classes, WEB-INF/lib/*.jar, or
> along the system class path.  See the servlet 2.2 specification for more
> details and examples.
>
> >
> > Thank you
> >
> > Arion
> >
>
> Craig McClanahan
>
> PS:  Tomcat 3.0 had a bug that prevented classes in WEB-INF/lib/*.jar from
> being found.  This has been fixed in more recent releases.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Re: How can I change the servlet path?

Posted by Shawn McMurdo <sh...@lutris.com>.
Hi Craig,
Do you happen to know the files involved in this fix?
We need to use 3.0 until 3.1 finalizes.
Thanks.
Shawn

"Craig R. McClanahan" wrote:

>
> PS:  Tomcat 3.0 had a bug that prevented classes in WEB-INF/lib/*.jar from
> being found.  This has been fixed in more recent releases.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

--
Shawn McMurdo              mailto:shawn@lutris.com
Lutris Technologies        http://www.lutris.com
Enhydra.Org                http://www.enhydra.org



Re: How can I change the servlet path?

Posted by "Craig R. McClanahan" <cm...@mytownnet.com>.
Arion wrote:

> Hi!
>
> The default local path for CONTEXT is <CONTEXT docbase>/web-inf/classes,
> am I right? How can I override the setting say <CONTEXT
> docbase>/servlet?
>

You are confusing the class path for a context (used to locate all Java
classes referenced by a web application, not just servlet classes) with the
URL that is mapped to a particular servlet.

The 2.2 servlet specification defines that all classes under
WEB-INF/classes (and all JAR files under WEB-INF/lib) become part of the
class path for a particular context.  However, this has nothing to do with
how you access servlets found in those directories via a URL.

If you use a URL like "/{context-path}/servlet/xxxxx", Tomcat looks for a
class named "xxxxx" in one of the above two locations, or along the system
class path if not found there.  It follows the usual Java rules for
resolving classes that are inside packages.

In addition, you can map a servlet to a specific path to a specific servlet
using <servlet-mapping> element in the web.xml file.  Again, the class
itself is located by looking in WEB-INF/classes, WEB-INF/lib/*.jar, or
along the system class path.  See the servlet 2.2 specification for more
details and examples.

>
> Thank you
>
> Arion
>

Craig McClanahan

PS:  Tomcat 3.0 had a bug that prevented classes in WEB-INF/lib/*.jar from
being found.  This has been fixed in more recent releases.