• 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

Loading property file values to a hash map

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have few jsp pages that need to display some selected values (key value pair) from a properties file at each page load. I thought I'm going to try something like below.
1- Have a servlet with overridden init method to read the file and load the key value pairs in to a hash map
2- Access the map from each page.
The problem is I couldn't figure out how to share the map to the jsp pages.

If I use a java class to load the key value map and return values when needed, I will have to read the property file, each time I create an instance of that class.

Thanks in advance for any suggestions / help to resolve this problem.
 
Greenhorn
Posts: 10
Python Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can the properties be loaded at startup time?

This way you can store these key-values into the ServletContext, every servlet can take it off the ServletContext and passing these values to the jsps.

I maybe wrong here, but I remember reading this in the Heads First book.

I hope I may be of help.

Cheers
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Kelvin is right. You can store your map as an attribute in servletcontext.
And sorvletcontext is accessible to each JSP, so you can use it. and if property is going to change per request then you can set map as attribute in session object.



-Chintan Patel
 
Sheriff
Posts: 67747
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
Why are you doing all these gymnastics when the JSTL <fmt:message> tag will do it for you?
 
Jayanath Amaranayake
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the replies. I'm going to use the ServletContext to hold my map and that prevents me loading the map again and again.
Bear, I looked in to <fmt:message> tag, but couldnt figure out how it would help me to solve the same problem. If you could elaborate it a little bit, that would be great.

Thanks again for your time.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic