• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Not Getting proper output for Servlet Application

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic