struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: java.lang.IllegalStateException: Cannot forward after response hasbeen committed
Date Fri, 28 Mar 2003 03:38:16 GMT


On Thu, 27 Mar 2003, Becky Norum wrote:

> Date: 27 Mar 2003 20:24:51 -0500
> From: Becky Norum <bnorum@coe.neu.edu>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> Subject: Re: java.lang.IllegalStateException: Cannot forward after
>     response hasbeen committed
>
> Thanks for all the reponses.
>
> It's actually a piece of code within a custom tag, so the scope probably
> isn't an issue.
>
> The tag checks to see if the user is a member of the group s/he is
> trying to access.  So, probably, some HTML response is output before the
> tag is called. (because a header file is included via jsp:include), but
> the tag is called at the top of the JSP page.
>
> So I hear y'all saying to call the tag before writing HTML, but that
> would require some significant rearranging.  Plus, sometimes it works
> just fine - actually, when I call the page directly it works, but when I
> do a forward it doesn't.
>
> So do I need to call the page directly rather than forward?
>
> Thanks so much,
>

There is a fundamental rule in the servlet API that things included with a
RequestDispatcher.include() call (which is what <jsp:include> does under
the covers) cannot modify the HTTP headers of the response.  Since you
need to modify those headers to do a redirect, that's going to be a
problem for your use case.

How about doing the include with <%@ include file="..." %> instead?  This
causes the included logic to become part of the calling page (sort of like
a #include directive in C/C++), so it can do what you describe (as long as
it's in the page near the top so you haven't overflowed the output buffer
yet).  As an extra added bonus, it's a little less overhead to do it this
way, too :-).

> Becky
>

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message