| Author |
Mapping addresses in jsp and servlets
|
Rajesh Khan
Ranch Hand
Joined: Oct 16, 2011
Posts: 224
|
|
|
I have 7 or 8 pages with common options like Home , Users etc. However when i change the address of home to something else then i have to go to each individual page and change the address both in servlets and jsp . Is there a way or a practice in which i could keep variables like Home_var some place. So that whenever i need to change an address i would just change that variable and all the links would pickup the address from that variable.
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
Just sounds like you need an IDE with a good implementation of search and replace.
How often do you make such changes? Certainly, a run-time solution would be rather silly for something that should be handled before building.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Rajesh Khan
Ranch Hand
Joined: Oct 16, 2011
Posts: 224
|
|
|
I am actually using Eclipse. I am not sure if its a runtime issue. What i mean is i need to keep a list of variables some where (Dont really know which place that would be??). Anyways these variables would have addresses attached to them like String Home = "index.jsp" . All my pages and servlets will have something like < a href=home>..</a> instead of <a href="index.jsp">..</a>. So is there some way i can accomplish this ?? OR is this a bad idea ??
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
Sure if you want to abstract the URLs for some reason there are any number of approaches. I personally wouldn't -- I don't see a real need for it and it could add an unnecessary level of obfuscation to the pages.
But if I were going to do this, I'd likely do it as follows:
Create a properties file that assigns URL values to keys.Use a context listener to read the properties file on startup, and create a Map from the key/value pairs.Place the Map in app context.Use an EL expression to reference the URL by its key.
|
 |
Rajesh Khan
Ranch Hand
Joined: Oct 16, 2011
Posts: 224
|
|
|
Any idea where that properties file should be placed ??
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
|
Easiest way is in the class path of the web app. WEB-INF/classes is a popular place.
|
 |
 |
|
|
subject: Mapping addresses in jsp and servlets
|
|
|