Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Not Getting proper output for Servlet Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not Getting proper output for Servlet Application" Watch "Not Getting proper output for Servlet Application" New topic
Author

Not Getting proper output for Servlet Application

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi All,

Actually I'm trying to wright a servlet application in which one servlet(MultipleInlcude.java) tries to include another
servlet(IncludeServlet1.java) which already has other jsp (level3.jsp) included in turn has another servlet (IncludeServlet2.java)
included.

My aim is to display output of all resource on single page.

But here i'm getting output of only IncludeServlet2.java. (Hello from Level4)

Follwing are the codes:

MultipleInclude.java
=============


IncludeServlet1.java
=============


level3.jsp
======


IncludeServlet2.java
=============


web.xml
======



Could anyone please explain me where its going wrong.
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
You can't commit to the response (i.e. write to the stream) and then forward it to another resource. Instead you can save the HTML as a request attribute.

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Ryan,
Thanks for your valuable input.
Could you please pin point where exacly it goes wrong and where the changes need to be made.

I understood your point that you can't commit response and then include(forward) page. But if its the case then i should get an Exception.

But in this case i'm not getting any exception.

Could yoy please explain in brief where the correction are to be made.

Thanks in Advance.
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
An IllegalStateException is thrown when you call OutputStream#flush before RequestDispatcher#forward, but you may not receive an error page.

See RequestDispatcher#include to accomplish your task.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
If I had been handed such a complex tangle of interlocking servlets and jsp I would say it is time to back off and redesign the whole thing. I bet there are functions inside servlet code that should be in helper classes that can be tested outside the servlet environment.

Sometimes you just have to throw version 0.1 away and start anew.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not Getting proper output for Servlet Application