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
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply 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: 310
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: 56157
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 310
Thanks a lot !
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Dynamically changing url mapping for a servlet/jsp? Can I use filters?
 
Similar Threads
sessionid() returning different values
Problem with posting data from one servlet to another servlet in a different application
Generating requests from servlets
Mapping a main Action Servlet to other servlets
Know which servlet is sending the request