• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ errata

 
Sayak Banerjee
Ranch Hand
Posts: 292
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a code snippet in HFSJ on page 236 demonstrating the use of encodeURL. There is a line which says:

out.println("<a href\"" + response.encodeURL("/BeerTest.do") + "\">click me</a>");


I don't think the URL string used would work....While tryin' out encodeURL() I found out that the forward slash "/" in "/BeerTest.do" actually denotes the web container and not the context root(web application).....it's similar with encodeRedirectURL() as well.... I checked in the errata list but its not there....Could anybody please confirm this?

Also, if this is true then usage of "/" with sendRedirect(), encodeURL(), encodeRedirectURL() would mean relative to the web container and the usage in everything else like getRequestDispatcher() in ServletRequest, etc. would mean relative to the context root(root of the web application).
Am I right?
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the path is a url-pattern of a servlet, then you must avoid /.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not true...the only instance where you don't use the "/" is when you use getNamedDispatcher() because in that case you use the servlet name and not the URI
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused. Let me try.
 
Khadija Lokhandwala
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i have figured it out.
In HFSJ ,page 236 the response.encodeURL should be "BeerTest.do" without the "/" slash for it to work.

In reponse, the forward slash "/" indicates relative to the Web Container.
In request, the forward slash "/" indicates relative to the WebApp.

(where request & response indicate HttpRequest & HttpResponse objects respectively)

If the conclusion is wrong, kindly let me know.
Thank You
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing encodeURL does is add the session ID to the end if it's needed. It doesn't care about slashes.

In fact, I bet it won't even care if you call response.encodeURL("I am a Y@nk33 d00d13 d4ndy!!!");

I think you are getting encodeURL confused with other methods that accept a String url parameter like response.sendRedirect and request.getRequestDispatcher - I clarified the difference between those other two here.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic