我正在尝试根据当前处于 Activity 状态的 module
修改我的页面的外观。所以基本上,我有一组通用的 jsp 页面,需要根据模块更改磁贴。
我能够独立实现每个模块的基本图 block 。这需要我在 jsp 中指定磁贴的定义。所以我的问题是,我怎样才能更改定义,从而让图 block 根据模块动态变化。
我在 Struts 1.1 中使用 Tiles(不是我的选择,但要求是这样的),并且是这个框架的新手。
编辑:我试过浏览文档、浏览其他论坛和博客,但没有遇到类似的情况。有没有其他方法可以实现这一点,可能无需切换 tile 定义?
最佳答案
我从您的问题中了解到,您将在 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) 中,tile 将被定义为类似
<%@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>
关于java - 在 Struts 中动态修改 tile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14623326/