File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Dynamically changing url mapping for a servlet/jsp? Can I use filters? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Dynamically changing url mapping for a servlet/jsp? Can I use filters?" Watch "Dynamically changing url mapping for a servlet/jsp? Can I use filters?" New topic
Author

Dynamically changing url mapping for a servlet/jsp? Can I use filters?

Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Hi,

I have an un-usual requirement:
I need to change the 'url mapping' of some servlets/JSPs, *but* this must be done dynamically.

i.e. : suppose my end-user opens up a browser and asks to see 'http://myHost/myWebApp/hello'
Then on some condition I need the request to be handled by ServletA, on other conditions - ServletB.
(Please don't ask why - it's a painful story, involving security, ancient content-management tools, and stupid management).

Theoretically, I could have a single servlet with some 'if' condition, but that's maintenance nightmare. I'd rather have 2 separate Servlets (ServletA, ServletB) and some external point of decision that would direct the requests to either one of them.

Could anyone please recommend the best way to do it?

1. Is there some built-in support for this, in the servlet/JSP specification ? I would even settle for vendor-specific solutions (preferrably, Tomcat or Websphere).

2. Could I achive this with a Filter (that is, javax.servlet.Filter) ?
If so, could anyone please tell which syntax/method to use ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

You can't change the mapping, but you could use a filter to forward the request to either servlet based upon whatever decision you might make in the filter.

I do this all the time for authenticated pages. A filter determines if the user is logged in or not (based upon whether an authentication token has been placed on the session) and forwards them to the requested resource if so, or forwards them to the "show me the login page" controller if not.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Thanks a lot !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamically changing url mapping for a servlet/jsp? Can I use filters?