Forums Register Login

Q: Data type for JSP implicit objects

+Pie Number of slices to send: Send
Q:

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.
e ServletConfig for both.

The answe to this question is c, but in my opinion it should be d.

The exaplination which is given for answer-c is as follows:
-----------------------------------------------------
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.
-----------------------------------------------------

But as per JSP 2.0 specification data type for request and response is HttpServletRequest and HttpServletResponse respectively.

Please advise.
+Pie Number of slices to send: Send
I thought it would be HttpServletRequest

However JSP are also designed to use other prtocols then HTTP.
So that is probable why it is the more generic ServletRequest
+Pie Number of slices to send: Send
Hello,
ServletRequest has setAttribute() method.

the feature of storing attributes is common to all servlets and jsps and not just HttpServlets and JSPs for HTTP



This explanation is correct.

Although HttpServletRequest extends ServletRequest whenever the container implements the HttpServletRequest interface {which means makes an HttpServletRequest class} it won't give the implementation of setAttribute in it. Rather the implementation of the setAttribute will be in the ServletRequest class that the container makes.

Also it is very unlikely that some one will code a Servlet that is not HTTP but the feature is still there for others who do want to code a non Http Servlet.

Hope that helps.
Hug your destiny! And hug this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1033 times.
Similar Threads
JSP implicit Object HttpServletRequest or ServletRequest ?
From JWebPlus reg jsp scopes
types of implicit variabless
A Speculation
DOUBT on a question JSP SCOPES
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:55:12.