This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher

 
sandeep Talari
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RequestDispatcher view
=getServletcontext().getRequestdispatcher("/result.jsp");

as you know this the request dispatcher for the context.But why it should and must start with "/".why there is no compulsion for the request.getRequestDispatcher("result.jsp");

i know that if we give "/" , it mean that search from the contextRoot of web application.

please explain ,
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have the Answare sandeep.

Originally posted by sandeep Talari:
i know that if we give "/" , it mean that search from the contextRoot of web application.


because here you are using servletContext to forward. so it is related to the contextroot
 
Shahnawaz Shakil
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It makes sense because ServletRequest has a current request path to evaluate the relative path while ServletContext does not.
 
Michael Ku
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getServletcontext().getRequestdispatcher("/result.jsp");

If you get the RequestDispatcher from the ServletContext then you cannot use a relative path (no / at the beginning of the path) because that would mean that you are saying to locate the resource relative to youself which is the ServltContext. Relative to yourself has no meaning. This is why you use the / at the beeginning of the path.

If you get a RequestDispatcher from your servlet, then the idea of relative to yourself means where on the file system the servlet is located and you can indicate a resource relative to yourself (no / at the beginning of the resource path) or relative to the web app (Context root) by starting the repurce path with a /.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64184
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

This is, in fact, the second topic named simple "RequestDispacther" posted today.

Please go back and change your post to add a more meaningful subject by clicking the .
 
Rohith Kumar Singh
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A path with preceding '/' will be relative to the underlying context of the current web application whereas a path without preceding '/' will be relative to the current request.

Cheers,
Rohit
[ August 27, 2008: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic