• Post Reply Bookmark Topic Watch Topic
  • New Topic

How write for JSP inclusion?  RSS feed

 
Jessica Doe
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to include the text output of a servlet in a JSP file like this:

<jsp:include page="RandomText" flush="true" />

In the RandomText servlet, I am currently doing this:

PrintWriter out = response.getWriter();
try
{
out.print (outputString);
}
// out.close();

If I try to close out, it blows! So, what is the proper way to generate the servlet output to be included in a JSP?

Thanks!
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The included servlet should not close out because control will return to the JSP when the servlet is done executing. The JSP might need to use out and you should put the close in the JSP after control returns to it.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why use a servlet for this purpose rather than a custom tag?
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jessica Doe:

PrintWriter out = response.getWriter();
// out.close();

If I try to close out, it blows! So, what is the proper way to generate the servlet output to be included in a JSP?

Thanks!


And in general, if you are not opening the output stream yourself, you should not close it, unless you have a very good reason to do so.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!