2012-12-07 53 views
5

是否可以在Struts 1中使用Tiles2?如何在Struts 1中使用Tiles2 1

我已經按照提供的遷移指南http://tiles.apache.org/migration/index.html

但指令,當我嘗試訪問我的行爲,我得到這個錯誤:

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

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

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

回答

1

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

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

查找的Tiles2插件here來源。

-2

是它可以使用它與支桿1. Check their site

認沽屬性瓷磚文件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> 
+0

這是瓷磚1解決方案,我需要使用瓷磚2 –