Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getRequestDispatcher() method  RSS feed

 
bobby reddy
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Could anyone explain the difference between getRequestDispatcher() method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

Thanks,
bobby
 
Khirod Patra
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.servlet.ServletRequest:- In this interface the getRequestDispatcher(String path) take the path of the resource to include or Forward, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.

But In case of javax.servlet.ServletContext, It cannot accepts relative paths
all the path must start with "/" which relative to the current context root

Cheers
Khirod patra
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

relative path comes with 2 flavour

1.starts with "/"

2.without "/"

so, can you explain me that how you are saying context not accepting relative path

thanks & Regards,
seetharaman.v
 
Gopikrishna Kunisetty
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by bobby reddy:
Hello,
Could anyone explain the difference between getRequestDispatcher() method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

Thanks,
bobby


RequestDispatcher from ServletRequest object takes a string path for the resource to which you are forwarding the request. If you supply a "/" at the beginning of the path, container will look for that resource from the root of the web app. If you don't specify a "/" it will look for the resource relative to the request.
RequestDispatcher from ServletContext takes a String path of the resource, which we are looking for. Here you have to specify "/" that means you can't give path relative the current source that got request.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!