• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Deep Gagan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2404
93
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have checked the APIs also

Where did you look ? There is a getSession() method in HttpServletRequest, and there is a getServletContext() in HttpSession.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic