• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem accessing a servlet context attribute from an action servlet.

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic