• 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

RequestDispatcher clarfication

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I need clarification:





All the above 3 giving me the same result. i am unable to understand exactly how they(getServletContext() and request) differ.

Regards,
Ravi
[ May 03, 2008: Message edited by: Garla Ravi ]
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You can create a RequestDispatcher in either way. If your Servlet doesn't extend HttpServlet then the only way to get a RequestDispatcher is thought the ServletContext.

when you get a RequestDispatcher throught ServletContext then you MUST start the path with a /. the path is treated as relative to the current context root.
you cah check the API
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you get a request dispatcher from servlet context, you have to start the path with a "/" because here there is no concept of any relative path. The container will look for the resource with respect to the application root.

When you get a request dispatcher from request then, you can give the resource path with or without "/" because here there is concept of relative path (relative to the request coming from the client). If the resource path starts with a "/" then the container will look from the app root. If the resource path is without "/" the container will look with respect to the request path.
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replies, but i am not quite convinced with your answers, as i found similar replies when i google. Requesting for appropriate reply, which is not covered in book or in APIs.

Fist I will put on what i understood.


There is absolutely no difference between above two, apart from objects which the getRequestDispatcher() method is called.

From my example relative/logical paths are no were given importance, they are treated as same.

am i correct ? please clarify.
 
Your mother was a hamster and your father was a 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