简体   繁体   中英

How to use Tiles2 with Struts 1

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>

Make the following changes in your struts-config.xml

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

Find the sources for the Tiles2 plugin here .

Yes its possible to use it with struts 1. Check their site .

Put attributes in you tiles file for mainTemplate Like:

<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>

If this did not work then try change your struts-config.xml like:

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM