• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Dispatcher, relative and absolute URLs

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
request.getRequestDispatcher("bbb");
[ February 28, 2007: Message edited by: Tridib Samanta ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic