File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Problems with jsp:include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problems with jsp:include" Watch "Problems with jsp:include" New topic

Problems with jsp:include

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Hi guys. I have been using my web application with this include:
<jsp:include page="/leftNavigation.jsp" flush="true"/>
but now I'm getting this strange error: Error: Attempt to clear a buffer that's already been flushed.
So, What I did was to increase the buffer size to 14kb:
<%@ page buffer="14kb"%>
and instead of using <jsp:include>, now I'm using
<%@ include file="/leftNavigation.jsp"%>
but the problem persists... any ideas ??

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

The preferred solution is to find the problem and fix it. Increasing buffer sizes is merely a work around (IMO etc)
From my experience this problem is usually caused by an exception being thrown after the buffer has filled. If you keep the JSP code small and stable (MVC etc) it reduces this. If you can find the exception you can manage it and stop the problem occuring.
(careful use of terminolgy: note that I didn't say 'handle' it. I'm not necessarily saying you should just put a try/catch around it)
It also helps to get any scriptlet coding that might throw an exception done first.
Not necessarily immediately useful, but I hope this helps.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Thanks David.
The problem was that in my servlet I was generating a token and was putting it in the request. In the jsp page I was checking the request and if the token was not there I was forwarding the request again to the servlet, so the token could be generated.
But, I forgot that response.sendRedirect creates a new request, so I was losing my token...
anyway... thanks for the tip. no need to resize the buffer
I agree. Here's the link:
subject: Problems with jsp:include
It's not a secret anymore!