This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Tiles problem" Watch "Tiles problem" New topic
Author

Tiles problem

Funicelli Aldo
Greenhorn

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="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>


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

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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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
Greenhorn

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:
<META HTTP-EQUIV="REFRESH" content="0;URL=http://www.genialloyd.it/homepage.jhtml">

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

Aldo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tiles problem