5

Is it possible to use Tiles2 with Struts 1?

I've followed the instruction available at the migration guide http://tiles.apache.org/migration/index.html

But when I try to access my actions, I get this error:

org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found.

I have in struts-config.xml:

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"
    maxFileSize="10M" tempDir="/tmp" />

<plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
</plug-in>

And tiles-defs.xml

    <definition name="mainTemplate" template="/common/templates/mainTemplate.jsp" />
    <definition name="index" extends="mainTemplate">
        <put-attribute name="body" type="string" value="/views/index/index.jsp"  />
    </definition>
4

2 回答 2

1

在您的struts-config.xml中进行以下更改

<controller processorClass=”org.apache.struts.tiles2.TilesRequestProcessor”/>
<plug-in className=”org.apache.struts.tiles2.TilesPlugin” >

在此处查找 Tiles2 插件的源代码。

于 2012-12-17T19:11:08.497 回答
-2

是的,它可以与 struts 一起使用 1.检查他们的网站

将属性放入 mainTemplate 的切片文件中,例如:

<definition name="mainTemplate" path="/common/templates/mainTemplate.jsp">
    <put name="title"  value="Tiles Example" />
    <put name="header" value="/header.jsp" />
    <put name="menu"   value="/menu.jsp" />
    <put name="body"   value="/body.jsp" />
    <put name="footer" value="/footer.jsp" />
</definition>

如果这不起作用,请尝试更改您的struts-config.xml喜欢:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">

<struts-config>

    <action-mappings>

        <action
            path="/User"
            type="org.apache.struts.actions.ForwardAction"
            parameter="/pages/user/user-form.jsp"/>

    </action-mappings>

    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
        <set-property property="definitions-config"
        value="/WEB-INF/tiles-defs.xml"/>
    </plug-in>

</struts-config>
于 2012-12-18T10:26:08.307 回答