• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher.getNamedDispatcher() motivation

 
Mike Mitchell
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

What is the motivation for RequestDispatcher.getNamedDispatcher()? I see in the API it 'Returns a RequestDispatcher object that acts as a wrapper for the named servlet.' I'm having trouble imagining what the value of having a wrapper for a named servlet is. (And furthermore how it might bear on HFSJ CH5#12, given below.)

Thanks,
Mike

Which statements about RequestDispatcher are true (where applicable, assume the RequestDispatcher was not obtained via a call to getNamedDispatcher())?
(*) A. A RequestDispatcher can be used to forward a request to another servlet.
B. The only method in the RequestDispatcher interface if forward().
C. Parameters specified in the query string use to create a RequestDispatcher are not forwarded by the forward() method.
D. The servlet to which a request is forwarded may access the original query string by calling getQueryString() on the HttpServletRequest.
(*) E. The servlet to which a request is forwarded may acces the original query string by calling getAttribute("java.servlet.forward.query_string") on the ServletRequest.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Mitchell wrote:What is the motivation for RequestDispatcher.getNamedDispatcher()? I see in the API it 'Returns a RequestDispatcher object that acts as a wrapper for the named servlet.' I'm having trouble imagining what the value of having a wrapper for a named servlet is. (And furthermore how it might bear on HFSJ CH5#12, given below.)

There are few differences however. Except for servlets obtained from getNamedDispatcher(), a servlet that has been invoked by another using either forward or include has access to some request attributes. (javax.servlet.forward.request_uri, javax.servlet.include.request_uri etc...). And also getNamedDispatcher() should point to a servlet declared in the web.xml by its name.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic