我从您的问题中了解到的是,您将在 tiles-defs.xml 文件中为 1 个 JSP 定义 2 个定义。像
<definition name="outputPage" extends="mainLayout">
<put name="title" value="HELLO" />
<put name="body" value="/pages/Welcome.jsp" />
</definition>
<definition name="outputPage2" extends="mainLayout">
<put name="title" value="HELLO2" />
<put name="body" value="/pages/tile2.jsp" />
</definition>
我建议实现您的要求的一种方法是在属性中设置模块类型(例如request.setAttribute("module", "module2");
)。
假设您将在 struts-config.xml 中为同一个 JSP 页面进行 2 次转发。
<action
path="/Welcome"
forward="/pages/tileTest.jsp"/>
<action
path="/customerAction"
type="xyz.actions.CustomerAction"
name="customerForm"
scope="request">
<forward name="tile" path="/Welcome.do"></forward>
<forward name="customer" path="/pages/customer.jsp"></forward>
</action>
然后在您的 JSP 页面(tileTest.jsp)中,这些图块将被定义为
<%@page language="java" pageEncoding="shift-jis"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<logic:notEmpty name="module">
<logic:equal name="module" value="module1">
<tiles:insert definition="outputPage" flush="true" />
</logic:equal>
</logic:notEmpty>
<logic:notEmpty name="module">
<logic:equal name="module" value="module2">
<tiles:insert definition="outputPage2" flush="true" />
</logic:equal>
</logic:notEmpty>
<logic:empty name="module">
<tiles:insert definition="outputPage" flush="true" />
</logic:empty>