Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!