wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Different ways to access the application’s ServletContext object in a servlet 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 "Different ways to access the application’s ServletContext object in a servlet" Watch "Different ways to access the application’s ServletContext object in a servlet" New topic
Author

Different ways to access the application’s ServletContext object in a servlet

Deep Gagan
Greenhorn

Joined: Aug 03, 2007
Posts: 11
In Niko's exams there is question
Q# 7 How can a servlet access the application’s ServletContext object? (3 correct answers)
a. getServletContext();
b. request.getServletContext();
c. response.getServletContext();
d. getServletConfig().getServletContext();
e. request.getSession().getServletContext();

Answer given is a,d,e

But i feel answer should be a,d only ....i have checked the APIs also ...Can somebody comment on this ?


Thanks & Regards
SCJP, SCWCD
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1665
    
  25

Hi Deep,

e is correct because you can get to it via the HttpSession object, it has a method:
ServletContext getServletContext(),
see API

Regards,
Frits
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

i have checked the APIs also

Where did you look ? There is a getSession() method in HttpServletRequest, and there is a getServletContext() in HttpSession.


[My Blog]
All roads lead to JavaRanch
 
jQuery in Action, 2nd edition
 
subject: Different ways to access the application’s ServletContext object in a servlet