0

I had a weird problem today. I have a head.jsp ( ending with out.flush ) which is being included by other pages. most of the pages doesn't have problem with this out.flush(); but one of my page is failing with IllegalStateException on jboss 4.2.2 GA.

I checked the related java file ResponseFacade.java I think. And see that problem occurs because of if (isCommitted) check.

I just removed the include statement from my problemmatic page and it is working now. But the question is; why the other pages does not have problem with this page while the only one page has ?

or if a jsp file is being included by other pages. do I need to out.flush() in this included pages ?

Olgun Kaya
  • 2,519
  • 4
  • 32
  • 46
  • You don't **need** to flush in JSP. Flush is there to send some content to the client **before** whole page is rendered. But the content will be flushed at the end anyway, even if you don't write `flush` explicitly. – bezmax Dec 30 '11 at 14:06

4 Answers4

2

Your web container will of course flush the response's output stream when it needs to. You don't need any call to flush. BTW, Java code in JSP is bad practice anyway.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • if you mean ResponseFacade stuff it is the part of app server not my jsp page. – Olgun Kaya Dec 30 '11 at 14:35
  • Your JSP page is certainly doing something that can't work if the output is already flushed (like a redirect, for example). What my answer is saying is that you don't need to flush manually. The app server will do it for you. – JB Nizet Dec 30 '11 at 15:07
1

I don't have the same setup but had a similar problem.

With <% out.flush(); %> in my jsp, <jsp:include page="abc.jsp" /> wasn't working any more. The specified page was not included.

I solved it by using <%@ include file="abc.jsp" %>

Hope this helps.

Christian
  • 1,487
  • 1
  • 14
  • 11
0

When you flush() you send the content of the buffer to the client and then empty the buffer. There is no bad practice in that, you can flush as many times as you need.

Just remember that the 1st flush() of a JSP page will send also the HTTP HEADERs, and the buffer is marked as committed (status -> isCommitted). Meaning: at this point you can no more send HTTP HEADERs (like eg page_forward, cookies).

Chances are that you are trying to send some HTTP HEADER in the page after the flush() has been done (after the include).

kkk
  • 818
  • 8
  • 11
0

This is the only method that worked for me (JSP over Tomcat/Apache).

Main.jsp

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

Flush.jsp (blank)

<%
%>
access_granted
  • 1,807
  • 20
  • 25