wood burning stoves 2.0*
The moose likes Servlets and the fly likes Loading a file in a servlet at run time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Loading a file in a servlet at run time" Watch "Loading a file in a servlet at run time" New topic

Loading a file in a servlet at run time

Sonali Inamdar

Joined: Jul 13, 2004
Posts: 1

I have a simple servlet which reads an xml file in its init method.

This XML file has some name value pairs.

These are read in a hashmap in the init method.

This is a global hashmap which is used in the service method for some processing and logic building.

Without shutting down the servlet, if an admin changes this xml file which was read in the init method, how will I reload/refresh the hashmap at run time so that the newly added values can be used for the forthcoming requests.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12671
Put the code that reads the xml file in a separate method - called from init and also callable from other methods. If you grab the timestamp on the file when init reads it, it is pretty simple to compare the current file's timestamp with the one that corresponds to the hashmap data and decide whether or not to re-read the file.

Java Resources at www.wbrogden.com
I agree. Here's the link: http://aspose.com/file-tools
subject: Loading a file in a servlet at run time
Similar Threads
Access XML files from servlets
Tracking the JSP translation time
getWriter() has already been called for this response
In-memory hashmap refresh in servlet
web application - property file