Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher clarfication

 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • 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 ]
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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
 
Shiraz Khan
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic