RequestDispatcher is an interface which has two important abstract methods defined.
1. include()
2.  forward()
Both the methods are used to delegates the control
from one Servlet to another Servlet / JSP or
from one JSP to another JSP/Servlet .

How to create object of RequestDispatcher ?
This can be achieved in two ways:-

1. With HttpServletRequest object : It can be created by calling getRequestDispatcher(String resourceName) method  by HttpServletRequest object.

public void service(HttpServletRequest req,HttpServletReponse res){
    
           ......
    RequestDispatcher rd= req.getRequestDispatcher("xxx.jsp");

}

To know more about this click here..!!

2. With ServletContext object : It can be created by calling getRequestDispatcher(String resourceName) method by ServletContext object.

public void service(HttpServletRequest req,HttpServletReponse res){
    
           ......
    ServletContext ctx= this.getServletContext();
    RequestDispatcher rd= ctx.getRequestDispatcher("xxx.jsp");

}

To know more about this click here..!!

The above two ways will create the object of RequestDispatcher. To dispatch the control we need to call either include(req,res) or forward(req,res) with RequestDispatcher object. 

Note : To know the difference between getting RequestDsipatcher object with HttpServleRequest and ServletContext , Click Here..!!

Signature of forward(req,res) 

public void forward(ServletRequest req,ServletReponse res)
                        throws ServletException, IOException {
   
}

Forward() method has two parameter of ServletResquest and ServletResponse but we are storing HttpServletRequest and HttpServletResponse object as a parameter. 

It is possible because internally HttpServletRequest extends ServletRequest which means we can able to wrap HttpServletRequest object to ServletRqeuest reference.  This is same with HttpServletResponse and ServletResponse.

public abstract interface HttpServletRequest extends ServletRequest {  

}

Signature of include(req,res)

public void include(ServletRequest req,ServletReponse res)
                        throws ServletException, IOException {
   
}

Include() has same signature as forward() method has. Difference is with the operation.

Note : To know the difference between using include() and forward(),  Click Here..!!

34 comments:

  1. There are only two methods of RequestDispatcher interface, that is forward()
    and include()

    ReplyDelete
  2. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    Oracle Training In Chennai

    ReplyDelete
  3. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.


    MEAN stack training in Chennai

    MEAN stack training in bangalore

    MEAN stack training in tambaram

    MEAN stack training in annanagar

    MEAN stack training in Velachery

    MEAN stack training Sholinganallur

    ReplyDelete
  4. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Devops Training in Chennai

    Devops Training in Bangalore

    ReplyDelete
  5. I really like your blog. You make it interesting to read and entertaining at the same time. I cant wait to read more from you.
    python training in chennai
    python training in chennai
    python training in Bangalore

    ReplyDelete
  6. This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot. 

    java online training | java training in pune

    java training in chennai | java training in bangalore

    ReplyDelete
  7. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.

    Data Science course in rajaji nagar | Data Science with Python course in chenni
    Data Science course in electronic city | Data Science course in USA
    Data science course in pune | Data science course in kalyan nagar


    ReplyDelete
  8. I am happy to find this post Very useful for me, as it contains lot of information

    Guest posting sites
    Education

    ReplyDelete
  9. Nice Article,Great experience for me by reading this info.
    thanks for sharing the information with us.keep updating your ideas.
    Selenium Training in Nungambakkam
    Selenium Training Institutes in Vadapalani
    Selenium Training courses near me
    Selenium Training in Chennai

    ReplyDelete
  10. Nice idea,keep sharing your ideas with us.i hope this information's will be helpful for the new learners.
    vmware Training in Ashok Nagar
    vmware Training in Nungambakkam
    vmware Training in Vadapalani

    ReplyDelete
  11. Your story is truly inspirational and I have learned a lot from your blog. Much appreciated.

    python training in chennai | python course institute in chennai | Data Science Interview questions and answers

    ReplyDelete
  12. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in chennai

    automation anywhere online Training

    angularjs interview questions and answers

    ReplyDelete
  13. I’d love to be a part of group where I can get advice from other experienced people that share the same interest. If you have any recommendations, please let me know. Thank you.
    health and safrety courses in chennai

    ReplyDelete
  14. Thanks for sharing this information admin, it helps me to learn new things. Continue sharing more like this.
    Devops Training in Chennai | Devops Training Institute in Chennai

    ReplyDelete
  15. Thanks for posting this highly informative article. I feel glad about learning more about this concept. Maintain the number of posting and keep up the good work!
    Data Science Course in Chennai | Data Science Training in Chennai

    ReplyDelete
  16. Great blog thanks for sharing Finally, an SEO agency in Chennai that understands exactly what you need. Adhuntt Media knows advanced search engine optimization and branding like the back of their hand. Let’s kickstart your brand right here right now!
    digital marketing company in chennai
    seo service in chennai
    web designing company in chennai
    social media marketing company in chennai

    ReplyDelete
  17. Nice blog thanks for sharing Join the Karuna Nursery Garden family and be a part of our network of home gardeners. We can help you setup the perfect front yard for your family to relax in. Reach us out to get more information on our terrace garden consultants in Chennai too.
    plant nursery in chennai
    rental plants in chennai
    corporate gardening service in chennai

    ReplyDelete
  18. such a great word which you use in your article and article is amazing knowledge. thank you for sharing it.

    Learn Best Microstrategy Training in Bangalore from Experts. Softgen Infotech offers the Best RPA Training in Bangalore.100% Placement Assistance, Live Classroom Sessions, Only Technical Profiles, 24x7 Lab Infrastructure Support.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic