The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ServletContext object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ServletContext object?" Watch "ServletContext object?" New topic

ServletContext object?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10032


How can we access the servletcontext object from the HttpServlet??

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

Just simply call getServletContext().XXX

Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
Mahesh Desai
Ranch Hand

Joined: Apr 04, 2007
Posts: 76
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.


SCJP 1.4 | SCWCD 1.4 | SCBCD 1.3 | SCEA Part I - In Progress
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
even this is possible..


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Neo Phesus
Ranch Hand

Joined: Feb 22, 2007
Posts: 71
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...

Neo<br />CCNA, SCJP 1.5, SCWCD 1.4
I agree. Here's the link:
subject: ServletContext object?
jQuery in Action, 3rd edition