• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Questions related to final HFSJ mock exam

 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got a few questions on the final HFSJ mock exam

Though I got 82% in the exam, there were a few surprises in the exam for me:

1. The first one - the difference between response.encodeURL() and response.encodeRedirectURL(). I thought the former just appends the jsessionid to the end of the URL and returns it as a String and that the second one appends the jsessionid to the end of the URL and ALSO redirects to that URL. But it came as a surprise to me when I read the amswers at the back of the final mock exam that response.encodeRedirectURL() just adds the jsessionid to the end of the URL, but does NOT do a redirect. The answers said that we have to do response.sendRedirect(response.encodeRedirectURL(URLString)) to do the redirect. My question is if both response.encodeURL() and response.encodeRedirectURL() are both going to return the URL string with the jsessionid appended, then what is the problem if I do a response.sendRedirect(response.encodeURL(URLString)) rather that response.sendRedirect(response.encodeRedirectURL(URLString))

2. One of the answers say that jsp:root element is optional in JSP documents. My question is if you don't put it, how do you tell the container whether you are writing a JSP page or a JSP document??

3. Question number 12 I think will generate a run-time exception. They have returned a EVAL_BODY_INCLUDE from doStartTag() method of a classic tag whose body-content is declared as empty in the TLD. One of the bang boxes in the chapter clearly says that this should NOT be done

Let me know your views
 
David Bridgewater
author
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...

On 1 - as I understand it, encodeURL() and encodeRedirectURL() just affect the Strings passed in (they may or may not append jsessionid information); they definitely don't perform any redirection themselves. The reason for having two methods, not one, can be found in the API documentation for HttpServletResponse.encodeRedirectURL():

"Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separete from the encodeURL method."

On 2 - use of jsp:root is one of three approaches for telling a web application that it is dealing with a JSP document. Most web containers running at servlet 2.4/jsp 2.0 level will automatically interpret a file with a .jspx extension as a JSP document. Also, you can manualy specify in the deployment descriptor (using the <jsp-config> tag) which URL patterns should be interpreted as JSP documents.

Sadly, I can't help with 3.

HTH -

David.
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David, now I got 1 and 2. But the authors should have mentioned these in the chapters
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sathish,

when it was your first and only run than it was a good score with 56/69 (82%) (I had 45/69 )


I agree with you on your question 1. The explanation in HFSJ p. 237 really let someone expect an inherent response.encodeRedirectURL. The only hint that it is not the case is the title of this paragraph which says:
URL rewriting works with sendRedirect()


On question 2, David's explanation sound profound.

On question 3, I don't see why that should lead to a runtime exception (very user unfriendly), however I had choosen A. and hadn't the time to find out why the correct answer is C.

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