Two Laptop Bag*
The moose likes Struts and the fly likes Problem accessing a servlet context attribute from an action servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem accessing a servlet context attribute from an action servlet." Watch "Problem accessing a servlet context attribute from an action servlet." New topic
Author

Problem accessing a servlet context attribute from an action servlet.

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I need to be able to access (and ultimately replace) a servlet context attribute from within an action servlet that extends the MappingDispatchAction class. I cannot seem to get the right syntax to access the attribute so I can test if I need to update/replace it. I can provide code samples if needed, but was hoping this would be an easy issue to resolve.


Thanks in advance,
Scott
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It's pretty easy. Inside any method in your Action class, just code:

ServletContext servletContext = getServlet().getServletContext();

The Action class, which is an ancestor of your class has the getServlet() method that retrieves the instance of ActionServlet that called your Action class.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem accessing a servlet context attribute from an action servlet.