This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Mapping addresses in jsp and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Mapping addresses in jsp and servlets" Watch "Mapping addresses in jsp and servlets" New topic
Author

Mapping addresses in jsp and servlets

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
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

Joined: Jan 10, 2002
Posts: 60740
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
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

Joined: Jan 10, 2002
Posts: 60740
    
  65

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: 230
    Any idea where that properties file should be placed ??
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60740
        
      65

    Easiest way is in the class path of the web app. WEB-INF/classes is a popular place.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Mapping addresses in jsp and servlets
     
    Similar Threads
    change cursor to an hourglass
    array doubt
    Can you invoke a servlet on the context path page?
    & in url parameter value
    Caching problem in jsps