aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getRequestDispatcher??? 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 "getRequestDispatcher???" Watch "getRequestDispatcher???" New topic
Author

getRequestDispatcher???

zena sam
Ranch Hand

Joined: Apr 26, 2002
Posts: 41
Which of the following statements about ServletContext.getRequestDispatcher(String) method and Request.getRequestDispatcher(String) method are true?
1.both are exactly same and can be used as per convienience
2.ServletContext.getRequestDispatcher(String) can take a relative path while the other can not
3.RequestDispatcher.getRequestDispatcher(String) can take a relative path while the other can not
4.Both calls are transparent to the browser
5.Both calls send a redirect message to the browser
3 and 4 are the correct answers according to JWebPlus...it's very confusing as I understand that context object takes relative path with a "/" in the parameter and request object is flexible with or without a "/" .
option 3 is very confusing as context object takes the relative path...
Can only one explain this....
Thanks in advance!!
Zena
raj sekar
Ranch Hand

Joined: Mar 11, 2002
Posts: 79
Hi Zena,
I hope the option 3 should be
3.Request.getRequestDispatcher(String) can take a relative path while the other can not
This is valid because getRequestDispatcher() of ServletRequest interface supports absolute as well as relative paths.
Thanks,
Raj


Thanks,
RajN - (SCJP,SCWCD,SCBCD,SCSA,IBM XML 142 )
http://www.geocities.com/n_rajasekar/index.html
You do what you love, love what you do and always deliver more than you promise
zena sam
Ranch Hand

Joined: Apr 26, 2002
Posts: 41
Thanks Raj!!
what am confused about the option 3 is "RequestDispatcher.getRequestDispatcher(String) can take a relative path while the other can not" and the context object does take a relative path only...
Thanks!!
raj sekar
Ranch Hand

Joined: Mar 11, 2002
Posts: 79
Nope, ServletContext can take only absolute path
not the relative path.
Please correct me if I'm wrong.
Raj
zena sam
Ranch Hand

Joined: Apr 26, 2002
Posts: 41
Thanks Raj!
can u point me to a good source for the Request Dispatcher concept...as in most of the tutorials/study guides it is mentioned as path relative to the context root, which confuses me to relative path...
Thanks!!
raj sekar
Ranch Hand

Joined: Mar 11, 2002
Posts: 79
You can refer Velmurgan's Guide.
http://www.geocities.com/velmurugan_p/index.html
Raj
zena sam
Ranch Hand

Joined: Apr 26, 2002
Posts: 41
Thanks Raj!!
Yu Chen
Greenhorn

Joined: Dec 03, 2001
Posts: 28
I found the javadoc on ServletRequest.getRequestDispatcher very confusing. http://java.sun.com/webservices/docs/1.0/api/javax/servlet/ServletRequest.html
On both places, it says, If path starts with /, it is interpreted as relative to the <i>context root</i>. For ServletContext, should it be <i>server root</i> instead? How can I get resource from other foriegn context then?


SCJP2<br />SCWCD
zena sam
Ranch Hand

Joined: Apr 26, 2002
Posts: 41
This is a nice article on redirection I found..
http://www.fawcette.com/javapro/2002_03/online/online_eprods/servlets_03_19/
hope it helps..
-Zena
Yu Chen
Greenhorn

Joined: Dec 03, 2001
Posts: 28
relative path: path relative to the current request.
absolute path: path relative to the context root.
By understanding the above terms, I finally clear that ServletRequest.getRequestDispatcher can take both absolute and relative path, but only within the same web application.
While servletContext.getRequestDispatcher can take only absolute path, it can be best used when you want to forward request to foreign context for cross web app communications.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getRequestDispatcher???