This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes scwcd doubt on jsp:forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "scwcd doubt on jsp:forward" Watch "scwcd doubt on jsp:forward" New topic
Author

scwcd doubt on jsp:forward

david rajaa
Greenhorn

Joined: Jun 20, 2007
Posts: 2
Dear ranchers,
Could you pls clarify my doubts on following topics

1. difference between RequestDispatcher.forward() and <jsp:forward>

In some notes I found
A <jsp:forward> effectively terminates the current page. Nothing before the <jsp:forward> or after the <jsp:forward> is written to the response! It is not the same when using a requestDispatcher.forward().

When I executed both performs same operation and I found no difference. Then what makes difference

2. what is the difference between <jsp:forward> and response.sendRedirect()
I suggest that <jsp:forward> works on server side and
sendRedirect() works on client side. Is it true

3. In Whizlab docs, they mentioned that any response committed after sendRedirect(),forward(), sendError() and so on results in IllegalStateException. Can I know the codes that leads to exception after these methods

4. In MZ notes, he mentioned
"When overriding doGet method, read the request data, write the response headers,get the response's writer or output stream object, and finally, write the response data"
when tried the code by placing setContentType() above getWriter() method, the code executed correctly. What happens to his statement

regards
david
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9470
    
    2

Hey, the difference between the two in short is that with RequestDispatcher.forward, the control is still within the method that makes the forward call but that method cannot write anything to the response and you can only write to the server console from within that method. With a <jspforward>, you cannot even write to the server log. All the control is taken over by the page to which you do the forward.

http://faq.javaranch.com/view?ScwcdHints


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Hi..

In case of <jsp:forward/> i.e. standard action tag..
the response is flushed..

While in case of RequestDispathcer, it's not so..

Regards..


rgrds,
Khushhal
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: scwcd doubt on jsp:forward