Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dispatcher, relative and absolute URLs

 
Rick Rangers
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My studybook tells me that the requestdispatcher you can get from a request
can handle both relative and absolute URLs and the requestdispatcher from the servlet context can handle only absolute URLs. My question is what exactly is the difference?

My guess that an absolute URL is a URL relative to the context root, but
in case of a servlet forwarding to a other servlet with a relative URL I have no clue what this URL might be relative to..

Thanks in advange,
Regards,
Rick
 
Kevin DesLauriers
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your text is referring to a context relative url as an absolute url and a relative url as a non-context relative url. When you get a requestDispatcher from a request it does not have to be from the context root (starting with a slash) but may. If you get a dispatcher from the servlet context it must start with a slash (context relative url)

Kevin
 
Rick Rangers
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I still don't get it completaly:

Suppose servlet A got invoked like this:

/myapp/aaa/bbb/test

where /myapp is the context path abd /aaa/bbb is the servlet path
and /test is the path info

(servlet mapping: /aaa/aaa/*)

now I would like to get a requestdispatcher to servlet B
(servlet mapping /aaa/bbb/*)

How would I do this using a non-context root relative url?

Any help would be appreciated!
Regards,
Rick
 
Rick Rangers
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, to many mistakes in the previous post here it is again:

Thanks!

I still don't get it completaly:

Suppose servlet A got invoked like this:

/myapp/aaa/aaa/test

where /myapp is the context path and /aaa/aaa is the servlet path
and /test is the path info

(servlet mapping: /aaa/aaa/*)

now I would like to get a requestdispatcher to servlet B
(servlet mapping: /aaa/bbb/*)

How would I do this using a non-context root relative url?

Any help would be appreciated!
Regards,
Rick
 
Tridib Samanta
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getRequestDispatcher("bbb");
[ February 28, 2007: Message edited by: Tridib Samanta ]
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure that would be possible, Rick.

If you could, your path would have to be "../bbb/something", and the servlet spec doesn't say whether or not it is legal to use ../ to step back a folder.

Head First says that you can't use ../../ (or however many folders deep you are) to step out of the current context into a different one. HF doesn't say that ../ is completely illegal, however.

I have to lean towards the philosophy of "If the spec doesn't say I can do it, I shouldn't try it" because, even if you get something not in the spec working in Tomcat today, your app might break if you move it to another container tomorrow. For your scenario, you're best off using the full context path... or start mapping your servlets with postfixes instead of those virtual folders.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic