• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clarifying path for Redirect & Dispatcher

 
Selvaraj Subramanian
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sarang bharambe
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic