• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

RequestDispatcher Doubt?  RSS feed

 
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

There are two ways we can get a RequestDispatcher, the second way is through the use of ServletContext and why is that we need a forward slash when we get the request dispatcher using ServletContext??

RequestDispatcher view = getServletContext().getRequestDispatcher("\sample.jsp");
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think because the behaviour of getRequestDispatcher method of ServletCOntext is defined that way, i.e. it takes path relative to the context root.

ServletRequest defines similar method which can accept relative paths.

So, if you are using ServletContext's getRequestDispatcher, that means the method would look for the servlet wirh path relative to the context root and hence you need to put "/" in the begining of the path string.

Thanks and regards,
Saurabh
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why is this behavior?? Also what is the difference between absolute and relative path?? Anyone on this please!
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any replied guys?
 
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carol,

That was an excellent reply. I'll be patient till someone helps me out. Anyways, thanks!
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolute path contains the server's ip address and port for example

http://www.mysite.com:8080/MyApp/admin/pages/login.jsp

now you can use


Whereas relative path means the path relative to your web application for example in above case you web app's context is "MyApp" and the equivalent to above will be

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali, that was crystal clear. Thanks for the explanation!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!