Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

getRequestDispatcher() method  RSS feed

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do we have getRequestDispatcher(String uri) in both the ServletRequest and ServletContext interfaces as both the serve the same thing.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API: HttpServletRequest.getRequestDispatcher(...)

The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html
 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletRequest.getRequestDispatcher(String uri) can take both the relative and absolute paths. But the ServletContext.getRequestDispatcher(String uri) can take only relative paths. So the Servlet.getRequestDispatcher(String uri) serves both the purposes. So what is the necessity for the giving a method with respect to context.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I prefer to make all references relative to the application context, but sometimes you can get into the situation where you aren't sure or it isn't easy to find out where you are inside that context (eg the current resource is included from somewhere else). In this case it may be easier or necessary to use a relative path.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!