Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirect requests with web.xml url-pattern

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

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:
http://127.0.0.1:8080/myApp/novo
http://127.0.0.1:8080/myApp/novo/
http://127.0.0.1:8080/myApp/novo/myfile.jsp

and not:
http://127.0.0.1:8080/myApp
http://127.0.0.1:8080/myApp/
http://127.0.0.1:8080/myApp/login.jsp

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.

<servlet-mapping>
<servlet-name>RequestDispather</servlet-name>
<url-pattern>/*/*</url-pattern>
</servlet-mapping>

Any help would be appreciated.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic