• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HFSJ errata

 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confused. Let me try.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic