You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Dr. Evil" <dr...@sidereal.kz> on 2001/11/03 09:40:32 UTC

servlet-mappings

I'm trying to do some fancy stuff with servlet mappings.  This
mechanism leaves a lot to be desired; specificly, it would be
amazingly useful to be able to do a getRequestDispatcher in some way
that bypasses the servlet mappings in the web.xml file.  Alternatively
it would be extremely useful to be able to call the jsp servlet from
within another servlet, but this doesn't seem to be possible.  rd =
request.getRequestDispatcher("jsp") never seems to work.

Anyway, here's the question:

I know there are prefix mappings, such as /foo/bar/, and extension
mappings such as *.foo, but it doesn't seem like it's possible to do
mappings like /foo/bar/*.baz.  This mapping seems to never hit.  Is
there a way to do that?

Thanks

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


DEFAULT servlet-mappings

Posted by Carl Dreher <fo...@arn.net>.
Hi,

I'm new to using TomCat and am trying to port an existing application
from Java Web Server.  I'm confused about the default "/servlet/"
mapping.  In the <home>/conf/web.xml file, while discussing the
'invoker' servlet, it says:

  <!-- The "invoker" servlet, which executes anonymous servlet
classes      -->
  <!-- that have not been defined in a web.xml file.  Traditionally,
this   -->
  <!-- servlet is mapped to URL pattern "/servlet/*", but you can map
it    -->
  <!-- to other patterns as well.  The extra path info portion of such
a    -->
  <!-- request must be the fully qualified class name of a Java class
that  -->
  <!-- implements Servlet (or extends HttpServlet), or the servlet
name     -->
  <!-- of an existing servlet definition.     

Darned if I've been able to get this to work!  I've been able to run

         <home>/MyApplication/MyServlet

but not

         <home>/servlet/MyServlet

I want to install some generic servlets that can be used across ANY
application.  Where should these go?  I've tried copying the
HelloWorldExample.class file from the examples to a variety of places
and then trying to run it via

         <home>/servlet/HelloWorldExample

but no luck.  I could do this pretty easily under JWS.  Can someone
point me in the right direction, (or the documentation that better
explains this?)

Thanks,

Carl Dreher

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: servlet-mappings

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On 3 Nov 2001, Dr. Evil wrote:

> Date: 3 Nov 2001 08:40:32 -0000
> From: Dr. Evil <dr...@sidereal.kz>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: servlet-mappings
>
>
> I'm trying to do some fancy stuff with servlet mappings.  This
> mechanism leaves a lot to be desired; specificly, it would be
> amazingly useful to be able to do a getRequestDispatcher in some way
> that bypasses the servlet mappings in the web.xml file.

Such as ServletContext.getNamedDispatcher()?

>  Alternatively
> it would be extremely useful to be able to call the jsp servlet from
> within another servlet, but this doesn't seem to be possible.  rd =
> request.getRequestDispatcher("jsp") never seems to work.
>

This would work with the named dispatcher method above, but what are you
trying to do with it?  Since you're not referencing a particular JSP page,
getting a dispatcher to the JSP servlet isn't particularly useful for
anything.  (Besides, there is not necessarily any such a thing as "the JSP
servlet" on other containers, so you are locking yourself in to Tomcat).

> Anyway, here's the question:
>
> I know there are prefix mappings, such as /foo/bar/, and extension
> mappings such as *.foo, but it doesn't seem like it's possible to do
> mappings like /foo/bar/*.baz.  This mapping seems to never hit.  Is
> there a way to do that?
>

The legal mappings are those defined in the Servlet Specification, which
I've given you the URL for before (hint hint :-).

  http://java.sun.com/products/servlet/download.html

As you will find, patterns like "/foo/bar/*.baz" are not legal servlet
mapping patterns.

In a servlet 2.3 environment, one option you have is to define a Filter
that is mapped to "/*" (i.e. it will process every request to this web
app).  In your Filter, you can examine the request URI and use a request
dispatcher to forward to whatever servlet you like (and totally bypass the
mappings of the servlet container itself).  Although most Filters pass the
request on to the rest of the chain, this is *not* required.

Effectively, your filter would define exactly the mappings *you* want.
And, because Filters are portable, you would not be locked in to a
particular container.

Craig


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>