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 clarifying path for Redirect & Dispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "clarifying path for Redirect & Dispatcher" Watch "clarifying path for Redirect & Dispatcher" New topic
Author

clarifying path for Redirect & Dispatcher

Selvaraj Subramanian
Ranch Hand

Joined: Jul 15, 2005
Posts: 37
Hi All,
Correct me if I am wrong...

As per my understanding (using Tomcat),

sendRedirect()
==============
1)the path can be relative or absolute(htt://www.javaranch.com)
2)if its relative path & does NOT start with "/" then its considered as relative to the current URL path.
3)if its relative path starts with "/" then its considered as relative to the CONTAINER root.

RequestDispatcher obtained from request object
==============================================
1)can accept only relative path
2)the path CAN start with or with out "/"
3)the path is considered as relative to the current URL path

RequestDispatcher obtained from context object
===============================================
1)can accept only relative path
2)the path SHOULD start with "/"
3)the path is considered as relative to the current URL path

am I correct?


Selvaraj.S<br />SCJP 1.4 -83%<br />SCWCD 1.4 - 85%<br />SCEA 4 Part 1(310-051) - 89%
sarang bharambe
Ranch Hand

Joined: Apr 01, 2005
Posts: 40
Dear Selva,

You are Correct as far as sendRedirect() is considered.

But


RequestDispatcher obtained from request object
==============================================
1)can accept only relative path
2)the path CAN start with or with out "/"
3)the path is considered as relative to the current URL path



1. Can accept relative or absolute path
2. Correct
3. It should depend on whether the path is relative or not



RequestDispatcher obtained from context object
===============================================
1)can accept only relative path
2)the path SHOULD start with "/"
3)the path is considered as relative to the current URL path



The pathname must begin with a "/" ie absolute and is interpreted as relative to the current context root.




Hope this clarifies the thing.

Regards,
sarang bharambe



SCJP 1.4 (86%)<br />SCWCD 1.4 (86%)<br />----------<br />If You dont succeed at first time,call it Version 1.0 !!!
Gaurav Gambhir
Ranch Hand

Joined: Mar 04, 2006
Posts: 252
sendRedirect()
==============
1)the path can be relative or absolute(htt://www.javaranch.com) --Right
2)if its relative path & does NOT start with "/" then its considered as relative to the current URL path. -- Right
3)if its relative path starts with "/" then its considered as relative to the CONTAINER root.--Right


RequestDispatcher obtained from request object
==============================================
1)can accept only relative path --Right
2)the path CAN start with or with out "/" -- Right
3)the path is considered as relative to the current URL path--Right




RequestDispatcher obtained from context object
===============================================
1)can accept only relative path -- Right
2)the path SHOULD start with "/" --Right
3)the path is considered as relative to the current URL path--No
This path must be relative to the root of the ServletContext

Reference
Selvaraj Subramanian
Ranch Hand

Joined: Jul 15, 2005
Posts: 37
Thanks Sarang Bharambe and Gaurav Gambhir...

I agree with Gambhir, the relative path is considered as relative to the context.

Sarang, the path we specify in requestDispatcher is relative path only.

From Spec
==========
The getRequestDispatcher method takes aString argument describing a
path with in thes cope of the ServletContext. <b>This path must be relative</b> to the root of the ServletContext and begin with a �/'.
[ June 16, 2006: Message edited by: Selvaraj Subramanian ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: clarifying path for Redirect & Dispatcher
 
Similar Threads
Path ... doubts!
requestDispatcher.forward() throws error when forwarded to #topic
Absolute, Canonical, and relative path
HFS Mack Exam Q22 - Page 772 - ResquestDispatcher - Is the answer correct?
path used in getRequestDispatcher()?