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

Tiles problem

Funicelli Aldo

Joined: Jan 08, 2003
Posts: 12
Hi all: I'm using tiles for my site. Inside the template I have inserted a scriplet that, in error case (when a session bean is absent, for example), forward to the error page.

This is the template:
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<logic:notPresent name="stack">
<jsp:forward page="../do/uscitaDialogo"/>

This one of the page:
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<tiles:insert page="/templates/templatepaginatransazionale.jsp" flush="false">
<tiles ut name="corpoPagina" value="/autocarro/autocarro000body.jsp"/>

What I get (when an error occurs and the scriplet is invoked) is the error page, with the message: Cannot forward after response has been committed

If I don't use tiles, but jsp only, everything works fine (the client is forwarded to the correct page).

Any suggest? Thanks
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
I believe the problem is that with Tiles, you first execute the layout page which first prints some HTML including the starting tag for <html>, some more HTML, then includes the contents of a tile, a second tile, more HTML, a third tile, etc. and finally prints out the closing </html> tag. Now, if your third or fourth tile decides that the user should be forwarded somewhere, you're screwed because the other JSP's have already sent their part of the generated HTML to the web browser. You might be able to work around this by setting <%@ page flush="false" %> on top of your JSP's but I have never tried that so I'm not sure whether it would work.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Funicelli Aldo

Joined: Jan 08, 2003
Posts: 12
I find this solution: I put the jsp page in a single line
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%><tiles:insert page="/templates/templatepaginatransazionale.jsp" flush="true">...

Inside the template page, instaed of forward to an Action, I use:
<jsp:forward page="/common/jumppage.jsp"/>

The /common/jumppage.jsp makes a refresh to the right url:

This works,but I don't know if there are other better alternative..

I agree. Here's the link:
subject: Tiles problem
It's not a secret anymore!