File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes a simple question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "a simple question" Watch "a simple question" New topic
Author

a simple question

Ravishanker kumar
Ranch Hand

Joined: Jul 20, 2006
Posts: 53
What will be output on page and server when test1.jsp will be requested?Why?

/*test1.jsp*/
<%
1. RequestDispatcher rd=request.getRequestDispatcher("/test2.jsp");
2. rd.forward(request,response);
3. out.println("After forward");
4. System.out.println("After forward");
%>


/*test2.jsp*/
<%
out.println("Test 2");
%>

I tried this with tomcat 5.5.
And answer is: �Test2� is printed on the page and �After forward� on server.
But I am confused If line 4 is executed then why there is no output for line 3?
Can anyone explain it?
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

After the call retun from the requestDispatcher forward method to the calling page the response is invalid. That means you can not write anything to response. But any other codes executed perfectly, but not recommended to do anything after this call in calling page.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Ravishanker kumar
Ranch Hand

Joined: Jul 20, 2006
Posts: 53
Thanks for reply.

I have some more queries regarding this.

Is the implementation of out.println() is server dependent?
Is there any possibility that it may throw IlllegalStateException because we are trying to send the response after committing?
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

I don't think so. Before the forward method returns,the response content is sent and committed, and closed by the container. So no effect on calling the method on the closed writer.

Thanks
 
 
subject: a simple question