This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext object?

 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

How can we access the servletcontext object from the HttpServlet??
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just simply call getServletContext().XXX
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.servlet.http.HttpServlet extends from javax.servlet.GenericServlet.
javax.servlet.GenericServlet implements the ServletConfig interface.
ServletConfig interface has getServletContext() method which returns a reference to the ServletContext in which the caller is executing.

So as Hendy said, you just need to call getServletContext() method.


Thanks,
Mahesh

-----------
SCJP 1.4 | SCWCD 1.4 | SCBCD 1.3 | SCEA Part I - In Progress
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even this is possible..

getServletConfig().getServletContext().getXXXX();
 
Neo Phesus
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Jothi Sankar...I am just curious to know what was the cause of that question or which immediate action made you ask the question?

Just that your thought process may kindle some more questions in my mind As it usually does with other questions...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic