• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mapping addresses in jsp and servlets

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Any idea where that properties file should be placed ??
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Easiest way is in the class path of the web app. WEB-INF/classes is a popular place.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic