wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP implicit Object  HttpServletRequest or ServletRequest ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP implicit Object  HttpServletRequest or ServletRequest ?" Watch "JSP implicit Object  HttpServletRequest or ServletRequest ?" New topic
Author

JSP implicit Object HttpServletRequest or ServletRequest ?

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

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 ?


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1629
    
  23

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

Joined: May 18, 2010
Posts: 634

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
Bartender

Joined: Apr 07, 2010
Posts: 1629
    
  23

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

Joined: May 18, 2010
Posts: 634

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
Bartender

Joined: Apr 07, 2010
Posts: 1629
    
  23

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
 
 
subject: JSP implicit Object HttpServletRequest or ServletRequest ?
 
Similar Threads
For JSP scopes of request and page, what type of object is used to store the attribut
types of implicit variabless
DOUBT on a question JSP SCOPES
A Speculation
Q: Data type for JSP implicit objects