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

 
Vallabhaneni Suresh Kumar
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.
 
David O'Meara
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!