You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Shawn McMurdo <sh...@lutris.com> on 2000/03/01 20:01:16 UTC

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

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