【问题标题】:How to use Tiles2 with Struts 1如何在 Struts 1 中使用 Tiles2
【发布时间】:2012-12-07 14:29:58
【问题描述】:

是否可以将 Tiles2 与 Struts 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>

【问题讨论】:

    标签: java tiles struts-1 tiles2


    【解决方案1】:

    在您的 struts-config.xml

    中进行以下更改
    <controller processorClass=”org.apache.struts.tiles2.TilesRequestProcessor”/>
    <plug-in className=”org.apache.struts.tiles2.TilesPlugin” >
    

    查找 Tiles2 插件 here 的来源。

    【讨论】:

      【解决方案2】:

      是的,它可以与 struts 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>
      

      【讨论】:

      • 这是 Tiles 1 的解决方案。我需要使用 Tiles 2
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2016-07-05
      • 2011-03-11
      • 2015-05-19
      • 1970-01-01
      相关资源
      最近更新 更多