在网上找到了一些很好的例子,它们将 Struts 2 与 Tiles 2 集成在一起。我注意到它们都使用来自单个动作类的通配符方法映射动作。有这样做的理由吗?当我将操作单独映射到多个类时,我的应用程序不起作用。在下面的代码中,lookUpAll
我添加了操作。其余代码来自我试图遵循的示例。
Struts.xml:
<struts>
<package name="default" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="*Link" method="{1}" class="action.LinkAction">
<result name="welcome" type="tiles">welcome</result>
<result name="friends" type="tiles">view</result>
<result name="office" type="tiles">office</result>
</action>
<action name="lookUpAll" class="action.LookupAll">
<result name="success" type="tiles">view</result>
<result name="error" type="tiles">lookFail</result>
</action>
</package>
</struts>
瓷砖.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/baseLayout.jsp">
<put-attribute name="title" value="Template"/>
<put-attribute name="header" value="/header.jsp"/>
<put-attribute name="menu" value="/menu.jsp"/>
<put-attribute name="body" value="/body.jsp"/>
<put-attribute name="footer" value="/footer.jsp"/>
</definition>
<definition name="welcome" extends="baseLayout">
<put-attribute name="title" value="Welcome"/>
<put-attribute name="body" value="/welcome.jsp"/>
</definition>
<definition name="view" extends="baseLayout">
<put-attribute name="title" value="View"/>
<put-attribute name="body" value="/DispSchedule.jsp"/>
</definition>
<definition name="lookFail" extends="baseLayout">
<put-attribute name="title" value="LookFail"/>
<put-attribute name="body" value="/lookUpFail.jsp"/>
</definition>
<definition name="friends" extends="baseLayout">
<put-attribute name="title" value="Friends"/>
<put-attribute name="body" value="/friends.jsp"/>
</definition>
<definition name="office" extends="baseLayout">
<put-attribute name="title" value="Office"/>
<put-attribute name="body" value="/office.jsp"/>
</definition>
</tiles-definitions>