Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object can access the ServletContext

 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which implicit object can access the ServletContext?

a. server

b. request

c. session

d. response

e. application

Source: SAI

What is your final answer?
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the answer is C, as HttpSession provides the getServletContext method.
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parth, look at a source like this one to find out which implicit JSP object is of what type and then try to see which object will have access to the ServletContext object...
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2418
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your final answer?


I would say: b,c and e

If the Session has a method getServletContext() then you can also access it via the request object (request.getSession().getServletContext().
The implicit object application has a getContext() method as well.

Regards,
Frits
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My answer was same as
k space's
specially because it was asked to select only 1 option.

I might have thought on Frits lines if more than one option was asked to be selected.

But

see their take

JSP Specification, Version 2.0 (section 1.8.3)

Option E is correct. The application implicit object is equivalent to the ServletContext.

Options B, C, and D are incorrect because these implicit objects are used to access other scopes.

Option A is incorrect because that implicit object does not exist.


So what shall we decide?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2418
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Options B, C, and D are incorrect because these implicit objects are used to access other scopes.

This sounds rather vague to me... they (without the response-object) can still get to the context..

Regards,
Frits
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the questions language is not right I feel, they did not write correctly what they wanted to ask.

it should have been
Which implicit object refers the ServletContext?


anyways I feel the doubt is in everyone's mind, so its resloved for me.

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parth Twari wrote:the questions language is not right I feel, they did not write correctly what they wanted to ask.


me too, thanks for sharing!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic