Hi,

Danny has well explained what is happening. The problem is that Struts RequestProcessor do a forward in response to the <forward> in the config file. If you use the Tiles servlet, your code should work because the TilesRequestProcessor check if the response has already been committed. If yes, TilesRequestProcessor do an include instead of a forward.

To be short, use the TilesRequestProcessor, and it should work ;-).

Cedric

Trieu, Danny wrote:

Think of the template.jsp is the servlet that currently running, and
rendering text in response to the broser. Your other section on the
template.jsp, the content and the header, do a dynamic include which in
result as a forward to the intented jsp. We all know that once the server
start writing to the response stream, any attemp to forward control to other
servlet will result with exception telling You that you can't do this.
Instead of wanting action class to something before the template attempted
to include the targeted jsp
You can use Tiles' controller class or action controller to do it.

Hope this would help

danny

-----Original Message-----
From: Ken Riley [mailto:kriley@;allconnect.com] Sent: Tuesday, October 22, 2002 2:19 PM
To: Struts Users Mailing List
Subject: [TILES] Problem using struts actions in tile's template


I'm probably being dense here (not an uncommon occurance) but I seem to be
unable to create a tile layout that uses multiple actions. I have a sample below that
I'm using to test. When I run this, I don't get any output for the header.do action call.
Ultimately I would like to have a layout that calls 4 or 5 actions but I'd
like to get my test app working first :).

--------struts-config.xml-------
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd";>
<struts-config>
<form-beans></form-beans>

<action-mappings>
<action path="/header"
type="com.mycompany.test.HeaderAction">
<forward name="success" path="/jsp/header.jsp"/>

</action>
<action path="/content"
type="com.mycompany.test.HeaderAction">
<forward name="success" path="/jsp/content.jsp"/>

</action>
</action-mappings>
</struts-config>
-------END struts-config.xml-----

------temptest.jsp---------------
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> <tiles:insert
template="/template.jsp">
<tiles:put name="title" content="Service Address" direct="true" />
<tiles:put name="header" content="/header.do" />
<tiles:put name="content" content="/content.do"/> </tiles:insert>
------END temptest.jsp-----------

------template.jsp---------------
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<html:html>
<head><title><tiles:get name="title"/></title>
</head>
<body>
<table align="left" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><tiles:get name="header" /></td></tr> <tr><td></td></tr> <tr><td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td></td>
<td><tiles:get name="content"/></td>
</tr></table></td>

</tr>
<tr><td></td></tr>
</table>
</body>
</html:html>
------END template.jsp-----------

------header.jsp-----------------
<h3>THIS IS THE HEADER!!!!</h3>
------END header.jsp-------------

------content.jsp----------------
<B>THIS IS THE CONTENT!!</B>
------END content.jsp------------

Note:HeaderAction and ContentAction are identical except for their name.
just used for testing
------ContentAction.java---------
package com.mycompany.test;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class ContentAction extends Action {

public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

return mapping.findForward("success"); }

}
-----END ContentAction.java------

The output I get (Struts 1.1b2/Tomcat 4.1.12)
[Exception in:/header.do] Cannot forward after response has been committed

[Exception in:/content.do] Cannot forward after response has been committed


Thanks for any help/suggestions!
--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@;jakarta.apache.org>

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




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

Reply via email to