• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in Head First Servlet JSP

 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 335, question number 14, the option C which is the correct option tells that request object of JSP is of type ServletRequest and response object is of type ServletResponse. These objects are of type HttpServletRequest and HttpServletResponse respectively. So is that an error in the book??

Also on page 397, the book says that the correct answers to the exercise are at the bottom of the page upside down. But there is nothing written at the bottom of that page in my book. Is that also an error in the book. I am having May 2008 reprint of Indian edition of that book...
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request object of JSP is of type ServletRequest and response object is of type ServletResponse. These objects are of type HttpServletRequest and HttpServletResponse respectively.

HttpServletRequest extends ServletRequest, so any object that is an instance of HttpServletRequest is also an instance of ServletRequest. The actual type (which can be determined by request.getClass().getName()) will be something different again.
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right that HttpServletRequest is a sub class of ServletRequest and HttpServletResponse is a sub class of ServletResponse. But I pointed this out as this might create confusion in someone's mind that you can't call the http specific methods on these objects like getParameter, get Cookies etc...
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm fairly certain that those objects are in fact of the HTTP varieties, so you could cast them if you were to use scriptlets. Which of course you're not, because that would not be good design :-)

But JSP/JSTL/EL has implicit objects to get at those data items, so you shouldn't need to anyway.
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Ulf you got me wrong. The objects are actually of type HttpServletRequest and response directly. You don't have to cast them. And you are right that we should not use scriplets in you JSPs.

Anyways my point was that the question might confuse someone. Request object is indeed a ServletRequest object as HttpSevletRequest is a sub-class of ServletRequest (same for response)...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ankit Garg:
request object of JSP is of type ServletRequest and response object is of type ServletResponse. These objects are of type HttpServletRequest and HttpServletResponse respectively. So is that an error in the book??


ya. i understand your point. i dont see the question in HFSJ

but to above the statement ,you are correct i think
[ December 09, 2008: Message edited by: seetharaman venkatasamy ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic