Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Doubt regarding forward method in request dispatcher

 
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. "
 
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?
 
Beware the other head of science - it bites! Nibble on this message:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic