You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Steve Madsen <st...@moonglade.com> on 2000/06/22 07:34:57 UTC
Replacing the default servlet except for some requests
I have what I think should be a fairly common situation, but I can't seem
to get Tomcat to behave the way I want.
I have a servlet I want to handle all requests, except for those with
static content (images, pure HTML). I have mapped the servlet to "/",
which replaces the default servlet. My problem is how to get Tomcat to
"undo" this mapping in the case of certain files. I have tried:
/images/* -> default
and this sort of works, except my URLs now need to be
"/images/images/foo.gif" in order to find the file /images/foo.gif in my
tree. This will break paths on my production server, due to the extra
"/images". (Apache handles static content before it ever gets to
Tomcat.) I've also tried:
*.gif -> default
This doesn't seem to have any effect at all. I know it doesn't go to my
servlet any longer, but I don't get the image I expect, and I can't find
any error messages in the Tomcat logs or the Tomcat console. If I ask for
the image directly, instead of it being in a page, an extra "/" gets tacked
on to the end of the URL, and then it *does* go to my servlet.
I don't want to resort to using some standard prefix ("/servlet") or
extension (".do") for servlet-handled requests. Is there any way to get
Tomcat to do what I want?
BTW, is there a good reason that the rest of the Jakarta mailing lists
aren't archived on the web site?
--
Steve Madsen <st...@moonglade.com>
Re: Replacing the default servlet except for some requests
Posted by co...@eng.sun.com.
> I have a servlet I want to handle all requests, except for those with
> static content (images, pure HTML). I have mapped the servlet to "/",
> which replaces the default servlet. My problem is how to get Tomcat to
> "undo" this mapping in the case of certain files. I have tried:
> /images/* -> default
"default" is not a portable or standard feature of tomcat. It used to work
for tomcat standalone, but in 3.2 it'll probably not work ( at least not
the way it did - there are 2 handlers, one for dir and one for static
files and none is a servlet ).
The spec doesn't require anything about this - you can of course define
your own "default" servlet - but it'll not work in all cases ( for example
it have no way to guess the user "welcome" files for dirs ).
> and this sort of works, except my URLs now need to be
> "/images/images/foo.gif" in order to find the file /images/foo.gif in my
Probably a consequence of the default servlet's implementation - it
expects "/" as servlet path, etc. It's the default servlet - it's not
supposed (or designed ) to work as a user servlet.
> tree. This will break paths on my production server, due to the extra
> "/images". (Apache handles static content before it ever gets to
> Tomcat.) I've also tried:
>
> *.gif -> default
Same. Don't use "default" - create your own servlet to serve static files
if you want.
Anyway - I don't think there is any "standard" solution for your
problem. If you use Apache you can write special mappings, and make it
forward only what you want.
For tomcat standalone - we try to support the standard, all "special"
mapping features will come after that. You can do any kind of mapping in
Interceptors - but again, it's not standard/portable.
Costin