File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to change values in servlet context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to change values in servlet context" Watch "how to change values in servlet context" New topic
Author

how to change values in servlet context

Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
hi... all
I m indulge in a project in which I have saved some values in servlet context that would be work for all user. and these values are picked from database.Servlet which save these values in servlet context, is loaded when server gets start.
my problem is that if any time I change the values in database then I 'll have to restart the server agin.
how can avoid this.
I m using tomcat 4.1 /oracle/wion 2000
please give me a suggession

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41604
    
  55
That's a basic cache problem - every time the backing store is updated, the cache needs to be invalidated. Maybe your code that changes the values can access a special URL in your web app that tells it to update its cache.


Ping & DNS - my free Android networking tools app
Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
thanks for it.
but my problem is that if there is any updation in database then the value saved in servlet context should get updated.If I restart the the server. then the servlet loaded agin with the updated values , but I want that without restarting the server servlet context should get updated.
thanks
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
If your servlet saves the values in the context upon startup (using getServletContext().setAttribute() I'm assuming), why not do the same whenever the data changes?

-Yuriy
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
^ note that this will not work if your application is distributed, since you'll have seperate ServletContexts.

-Yuriy
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41604
    
  55

but I want that without restarting the server servlet context should get updated.


That's why I suggested that the code that updates the value hits a special URL (in the same servlet context as your cache) that causes the value to be updated. If the change happens in code that's outside your control you may need to use a trigger on that DB table (although I wouldn't know how that could access a URL).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to change values in servlet context