• 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

properites file

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
iam working on a web application where i have to load the properties file and use those porperties in the application both in servlets and the jsp . I want the properties file to be loaded(On start up) when the application is deployed and should be accesible to all sessions commonly.Can anybody suggest any method as far as possible.and also it should be sensitive to changes to the propeties file and should be reflected into the application.


thank u

regards
jagadish
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suri,

I hope implementation of a ServletContextListener interface could solve your problem.Load the properties file in
public void contextInitialized(ServletContextEvent sctxte) method.

Regards,
Sujith
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and also it should be sensitive to changes to the propeties file and should be reflected into the application.

Do you mean that you want it to be sensative to changes while the application is running, or just at startup? If you are changing the values in the properties file while the application is running, and you want these changes to be reflected in the application, then I suggest that you may be using the concept of a properties file incorrectly. Data that can and does change during the lifetime of an appliaction should be stored in some type of datafile or database.

If you only want it to read informatin at startup, then the listener suggested in the previous post is exactly what you need.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by suri jagadish:
hi all,
iam working on a web application where i have to load the properties file and use those porperties in the application both in servlets and the jsp . I want the properties file to be loaded(On start up) when the application is deployed and should be accesible to all sessions commonly.Can anybody suggest any method as far as possible.and also it should be sensitive to changes to the propeties file and should be reflected into the application.


thank u

regards
jagadish



As one of the programmers replied in previous threads.you can use ServletContextListener for reading the property from the application context and then loading that into the java.util.Properties and then setting this property in the ServletContext so that this becomes visible to the whole application.
Another way that also might have drawbacks..but for some of my previous applications I have used this.

I make a servlet and in the web.xml entry I load the servlet on start up of the application. In the init() method of the servlet i do all the stuffs like loading the property from the file and then setting this into the ServletContext .soon after this is done I call the destroy() of the servlet.
That puts an end to the life-cycle of the servlet and by this time it has done its job.

cheers!
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


soon after this is done I call the destroy() of the servlet.
That puts an end to the life-cycle of the servlet and by this time it has done its job.



destroy() is a lifecyle method that would be called by the servlet container when its ready to recollect (garbage collect) the servlet instance. You can ofcourse call the destroy() from anywhere that you have access to the servlet object - its a public method after all. But the statement that, that call ends the servlet's lifecyle is very incorrect. OP (suri), if I were you, I would go by Paul's posting.

ram.
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic