This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping addresses in jsp and servlets

 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 230
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Any idea where that properties file should be placed ??
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65113
    89
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Easiest way is in the class path of the web app. WEB-INF/classes is a popular place.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic