wood burning stoves
The moose likes Tomcat and the fly likes Redirect requests with web.xml url-pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Redirect requests with web.xml url-pattern" Watch "Redirect requests with web.xml url-pattern" New topic

Redirect requests with web.xml url-pattern

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270

I want to redirect all requests having a servletPath (request.getServletPath) through a servlet called RequestDispather.

I.e. I want this request to be redirected to RequestDispather:

and not:

I am not sure how to define the url-pattern in web.xml:

N.B. I don't want to hardcode the folder "/novo/*" in servlet-mapping.


Any help would be appreciated.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

There's no "servlet path" in a URL. The Servlet path is what gets extracted from the URL by as part of the process of routing a URL to a servlet.

In other words, URLs that retrieve images, JavaScript, CSS, and so forth, don't have "servlet paths". Actually, they do, but it's to the server's builtin default servlet, which doesn't count.

If you try and define a servlet path of something like "/*" in web.xml, however, that would cause all of the above resource requests to be re-routed to the associated servet, since a URL is a URL until it gets routed somewhere. And if it gets routed to your servlet, it won't be routed to the default servlet. Meaning that you'd break all handling of image, javascript and CSS requests.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link: http://aspose.com/file-tools
subject: Redirect requests with web.xml url-pattern
It's not a secret anymore!