wood burning stoves 2.0*
The moose likes Servlets and the fly likes properites file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "properites file" Watch "properites file" New topic
Author

properites file

suri jagadish
Greenhorn

Joined: Sep 14, 2005
Posts: 19
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
Sujith Kanaparthi
Ranch Hand

Joined: Sep 04, 2005
Posts: 45
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
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
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.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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!


Rahul Bhattacharjee
LinkedIn - Blog
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


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.
 
GeeCON Prague 2014
 
subject: properites file