• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a simple question

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ravishanker kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic