Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher & forward method

 
Saurabh Saha
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please tell me what is the difference between RequestDispather and <jsp:forward > method. I know that we use these two method to forward a request to any other page within the context. I want to know which is better approach to use RequestDispatcher or <jsp:forward >

Thanks,
Saurabh
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP forward gets translated into requestDispatcher when the JSP is converted to servlet code.
 
Saurabh Saha
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben,
It means using RequestDispatcher is better than <jsp:forward >, please correct me, if I'm wrong.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it means it's exactly the same.
<jsp:forward > will be translated into requestDispatcher.forward in the generated servlet code.

If I were going to forward from a JSP (which I never do) I would use <jsp:forward> because it's cleaner looking than putting a scriptlet in my JSP code. Performance-wise, there is absolutely no difference.
 
Saurabh Saha
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben,

Now it's clear to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic