• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ - Doubt on p.296 / p.333

 
Olivier Croisier
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

I'd like to report an inconsistency in the Head First book (old edition). I've looked at the errata and didn't find anything on that matter...

I've noticed that :
- Page 296 : the "request" and "response" JSP implicit objects are of type "HttpServletRequest" and "HttpServletResponse"
- Page 333 (mock exam Q14) : in answer C, those objects are said to be of type "ServletRequest" and "ServletResponse".

Granted, the former are subtypes of the latter, but I think this would at least need some clarification. (The JSP specs themselves aren't that clear either)


Olivier
[ April 08, 2008: Message edited by: Olivier Croisier ]
 
Olivier Croisier
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone confirm which is the real type of those implicit objects, and tell me whether something must be corrected in the HFSJ book ?
 
John Pearson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the Tomcat generated code on page 295 of HFSJ. You'll see that the request and response objects available in the _jspService routine are simply the request and response objects passed in as parameters, so their types are HttpServletRequest and HttpServletResponse.

The spec says that request and response are "protocol dependent subtypes" of ServletRequest and ServletResponse. That way, JSP isn't tied to the HTTP protocol, so a container could in theory support another protocol. I don't know of any that do, though, so I think you're safe in assuming you'll be dealing with HttpServletRequest and HttpServletResponse objects.
 
John Pearson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, in regards to the question on page 333, I suppose that according to the spec, the answer would have to be ServletRequest and ServletResponse since there is a possibility that a container could support another protocol, and the objects wouldn't be Http objects. That could be what they were thinking, or maybe they were just trying to confuse us.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic