my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ServeltContext 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 "ServeltContext object" Watch "ServeltContext object" New topic
Author

ServeltContext object

Richard Rex
Ranch Hand

Joined: Sep 19, 2005
Posts: 100
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


"If you fail to plan, you plan to fail."<br /> <br />Chad<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS (next)
Kiran Joshi
Ranch Hand

Joined: Sep 04, 2005
Posts: 54
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.
Gunaselan Varathan
Ranch Hand

Joined: Nov 11, 2005
Posts: 30
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


Guna<br />SCJP 1.4 86<br />SCWCD 1.4 94
Rajkishore Pujari
Ranch Hand

Joined: Sep 03, 2005
Posts: 46
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

Joined: Sep 19, 2005
Posts: 100
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

Joined: Sep 03, 2005
Posts: 46
Hi,
getSessionContext() is deprecated. Not getServletContext(). Correct me if I am wrong.
Akshay Kiran
Ranch Hand

Joined: Aug 18, 2005
Posts: 220
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.
 
 
subject: ServeltContext object