Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tiles problem

 
Funicelli Aldo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Funicelli Aldo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic