File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ errata Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ errata" Watch "HFSJ errata" New topic
Author

HFSJ errata

Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
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?


Turn on, tune in, drop out.
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
If the path is a url-pattern of a servlet, then you must avoid /.


SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
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

Joined: Apr 19, 2006
Posts: 310
I am confused. Let me try.
Khadija Lokhandwala
Ranch Hand

Joined: Sep 11, 2007
Posts: 33
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


If you ask me anything I don't know, I'm not going to answer.<br />--Yogi Berra
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFSJ errata