• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP implicit Object HttpServletRequest or ServletRequest ?

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enthuware Mock Tests



For JSP scopes of request and page, what type of object is used to store the attributes?




Select 1 correct option.
a HttpServletRequest and ServletContext respectively.


b ServletRequest and ServletConfig respectively.


c ServletRequest and PageContext respectively.


d HttpServletRequest and PageContext respectively.
Although HttpServletRequest is a subclass of ServletRequest, the feature of storing attributes is common to all servlets and jsps and not just HttpServlets and JSPs for HTTP.

e ServletConfig for both.

The correct answer is c .
But as per specification HttpServletRequest is the JSP implicit object for request.
so, The correct answer must be D.
Am i correct ?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2438
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct answer is c .
But as per specification HttpServletRequest is the JSP implicit object for request.
so, The correct answer must be D.
Am i correct ?

No, the implicit object is of type HttpServletRequest. However the implicit object implements both HttpServletRequest and ServletRequest interfaces (HttpServletRequest extends ServletRequest).

The ServletRequest interface has the getAttribute() and setAttribute() methods, so c is correct.

Regards,
Frits
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Frits in the question its asked For JSP scopes of request and page
Shouldn't we choose D as correct answer.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2438
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Frits in the question its asked For JSP scopes of request and page
Shouldn't we choose D as correct answer.

If you want store an object in the request scope you have to use the methods that are defined in the ServletRequest interface, consequently you have to use an object that implements the ServletRequest interface. In the Http world you can use the object that implements the HttpServletRequest as it extends the ServletRequest interface, but in another non-http world you would only have to implement the ServletRequest interface.

Be careful with reading:
For JSP scopes of request and page, what type of object is used to store the attributes?
They don't mention that the JSPs are in the HTTP context, therefore the HttpServletRequest is not sufficient as it won't be of any help in the non-HTTP context...

More clear now?

Regards,
Frits

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so,If a similar question comes in Exam I should go for C Option.
There is no mention of Http or non-Http in the question .
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2438
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you should know that Servlets and JSPs are not necessarily made for HTTP only.

There is no mention of Http or non-Http in the question .

That is exactly why C is correct and D not, if HTTP was mentioned only D would be correct.

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic