Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem accessing a servlet context attribute from an action servlet.

 
Scott Updike
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic