• 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

ServeltContext object

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing the mock exam for the jiris.com and confused with one of their question which is shown below.

The ServletContext object are accessible from which of the following objects?

Please select three correct answers.

A : HttpServlet
B : GenericServlet
C : HttpSession
D : ServletConfig
E : ServletResponse

My Answer: A,B,D.

But the engine says its A,C,D. But when I read the explanation (shown below in bold), it seems that it's really the GenericServlet who has the access to ServletContext object and not HttpSession. Is this an error for the engine? or am I missing something here?

Explanation

The ServletConfig interface has a method called getServletContext() that returns a handle to the ServletContext object.

Since class GenericServlet implements ServletConfig, it can also access ServletContext through getServletContext(), this is also apply to HttpServlet, which is a subclass of GenericServlet class.

public ServletContext getServletContext()
Returns a reference to the ServletContext in which the caller is executing.

Returns:
a ServletContext object, used by the caller to interact with its servlet container
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm also agreed to you. The answers should be Generic,Http servlet & servletconfig only.

The explaination given by you is also exactly correct.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Richard,
The correct answer is A,C,D. because you can access the servelest context object from

GenericServlet.getServletContext()
ServletConfig.getServletContext()
HttpSession.getServletContext()


answer B is almost correct, since we could access the method by inheritance. if they asked to select 4 answers, then i might select B also.


so A,C,D is the correct answer
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Richard,
"A,B,C,D" are right answers.

C: ServletConfig interface has access to ServletContext from getServletContext()
B: GenericServlet implements ServletConfig, so you know that its right
A: HttpServlet extends GenericServlet, again correct answer
D: HttpSession interface also provides method getServletContext(), which returns the ServletContext to which that session belongs.
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kiran, Gunaselan, and Rajkishore,

Thanks for your ideas guys.

I've searched for the HttpSession API and found out that it has a method named getSessionContext() that returns the context in which the session is bound. But this method is already deprecated. So I think the best choice are HttpServlet, GenericServlet, and ServletConfig if the question asks for 3 answers. And just add the HttpSession if the question requires 4 answers.
I just hope this won't be the same case in the real exam.

Thanks again to you guys!
 
Rajkishore Pujari
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
getSessionContext() is deprecated. Not getServletContext(). Correct me if I am wrong.
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raj
you're right,
he got confused I guess
only getSessionContext is deprecated,
getServletContext is not

I think the question should have had 4 options as answers,
nothing to worry about Rex, as long as u have the specs to back you up, there's no need to worry about the answers in the mock engines,
the real exam will definitely be more consistent.
 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic