This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Struts and the fly likes Filters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Filters" Watch "Filters" New topic


Frank Bueckert

Joined: Mar 23, 2006
Posts: 8
I'm having a slight problem with one of my filters. Basically, it holds a servletcontext variable, where it stores some values on startup. This is done to speed up the program, so that it's not constantly reading the same values in per person, or per request.

So, that means the values are static until Tomcat's restarted. My question is, is there any way to access that servletcontext variable? I'm trying to add in a way to force a re-load of values, so that we don't need to restart Tomcat all the time.

Thanks for the help!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Yes, there is. In any Action class, just use the getServlet() method provided by the Action superclass to get a reference to the ActionServlet. From there you gan get the Servlet context and reference it's attributes like this:

String myAttribute = (String)getServlet().getServletContext().getAttribute("myAttribute");
[ June 15, 2006: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Frank Bueckert

Joined: Mar 23, 2006
Posts: 8
Perfect! Worked like a charm!

Thanks for your help.
I agree. Here's the link:
subject: Filters
It's not a secret anymore!