wood burning stoves 2.0*
The moose likes JSP and the fly likes RequestDispatcher & forward method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "RequestDispatcher & forward method" Watch "RequestDispatcher & forward method" New topic
Author

RequestDispatcher & forward method

Saurabh Saha
Ranch Hand

Joined: Dec 08, 2004
Posts: 52
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

Joined: Dec 11, 2004
Posts: 13410

JSP forward gets translated into requestDispatcher when the JSP is converted to servlet code.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Saurabh Saha
Ranch Hand

Joined: Dec 08, 2004
Posts: 52
Thanks Ben,
It means using RequestDispatcher is better than <jsp:forward >, please correct me, if I'm wrong.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 08, 2004
Posts: 52
Thanks Ben,

Now it's clear to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher & forward method
 
Similar Threads
How to catch exception from Servlet in error.jsp
Help with getOutputStream() Exception
IllegalStateException
Question From ScwcdHints..?
errors on javaranch scwcd hints page?