• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding forward method in request dispatcher

 
Vinay Kumar chowdary
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I was going through Mikalai Zaikin notes and came across the following lines about forward method in request dipatcher..can anyone please explain???

"The path elements of the request object exposed to the target servlet must reflect the path used to
obtain the RequestDispatcher. The only exception to this is if the RequestDispatcher was obtained
via the getNamedDispatcher method. In this case, the path elements of the request object must reflect
those of the original request. Before the forward method of the RequestDispatcher interface returns,
the response content MUST be sent and committed, and closed by the servlet container. "
 
Tha�s Manfrim Firmino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here the author is talking about the ServletContext and RequestDispatcher methods.
**The path elements of the request object exposed to the target servlet must reflect the path used to
obtain the RequestDispatcher.
--> public RequestDispatcher getRequestDispatcher(java.lang.String path) - path is the location for a resource. The pathname must begin with a "/" and is interpreted as relative to the current context root

** The only exception to this is if the RequestDispatcher was obtained
via the getNamedDispatcher method. In this case, the path elements of the request object must reflect
those of the original request.
--> public RequestDispatcher getNamedDispatcher(java.lang.String name) - name is a servlet or JSP name given via server administration or via a web application deployment descriptor
As you see , since the path is not specified, it must reflect those of the original request.

**Before the forward method of the RequestDispatcher interface returns,
the response content MUST be sent and committed, and closed by the servlet container.
-->After you get a dispatcher, considering that you are going to make a call to forward, after you forward, the resource is going
send a response and commit it in the end, and then returns.

Is it clear now?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic