【问题标题】:Error org.apache.tiles.TilesException: Attribute not found错误 org.apache.tiles.TilesException:找不到属性
【发布时间】:2014-06-24 00:15:52
【问题描述】:

我正在开发一个 Web 项目,我使用 Tiles 在一个 JSP 中包含多个 JSP。

我遇到了一个问题,我收到了TilesIOException

我有这个 JSP,名称为:mainpage.jsp,其中包含页眉、正文和页脚的所有 JSP。

我这里的 body 还应该包含一些其他 JSP,因此我也尝试在其中使用瓷砖,但没有运气。

这是图块中的结构和 XML 代码:

mainpage.jsp
----header.jsp
----body.jsp(mainpageBody.jsp)
--------bodybox1.jsp
--------bodybox2.jsp
--------bodybox3.jsp
--------bodybox4.jsp
----footer.jsp

tiles.xml:

<definition name="mainpage" extends="mainpageLayout">
<put-attribute name="title" value="Welcome" />
<put-attribute name="body" value="/mainpage/mainpageBody.jsp" />
    <put-attribute name="mainbox0" value="/bodybox1.jsp" />
    <put-attribute name="mainbox1" value="/bodybox2.jsp" />
    <put-attribute name="mainbox2" value="/bodybox3.jsp" />
    <put-attribute name="mainbox3" value="/bodybox4.jsp" />
</definition>

<definition name="mainpageLayout" template="/mainpage.jsp">
<put-attribute name="title" value="Template" />
<put-attribute name="header" value="/mainpage/header.jsp" />
<put-attribute name="body" value="/mainpage/body.jsp" />
<put-attribute name="footer" value="/mainpage/footer.jsp" />
</definition>

这是我的mainpageBody.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ page import="java.text.*,java.util.*"%>

<script type="text/javascript">
    function showRegisterUserPage() {
        $(".frontpageBodyContent").load("showRegisterPageRegisterAction");
    }
</script>
<div class="frontpageBodyContent">
    <div id="frontPageContentDiv">
        <table border="0" style="width:100%">
            <tbody>
                <tr>
                    <td>
                        <div id="bodybox1">
                            <tiles:insertAttribute name="bodybox1" />
                        </div>
                    </td>
                    <td>
                        <div id="bodybox2">
                            <tiles:insertAttribute name="bodybox2" />
                        </div>
                    </td> 
                </tr>
                <tr>
                    <td>
                        <div id="bodybox3">
                            <tiles:insertAttribute name="bodybox3" />
                        </div>
                    </td>
                    <td>
                        <div id="bodybox4">
                            <tiles:insertAttribute name="bodybox4" />
                        </div>
                    </td> 
                </tr>
            </tbody>
        </table>
    </div>
</div>

WEB-INF 文件夹包含:lib 文件夹、tiles.xmlweb.xmllib 文件夹不包含任何内容。

struts.xml:

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
    <constant name="struts.enable.SlashesInActionNames" value="true"/>
    <constant name="struts.action.extension" value=",action"/>
    
    <package name="default" extends="struts-default">
        <result-types>
            <result-type name="tiles"
                class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>
        
        <action name="*MainAction" method="{1}" class="com.x.web.action.MainAction">
            <result name="mainpage" type="tiles">mainpage</result>
            <result name="success">index.jsp</result>
        </action>
        
        <action name="*RegisterAction" method="{1}" class="com.x.web.action.RegisterAction">
            <result name="registeruserpage" type="tiles">registeruserpage</result>
            <result name="redirect" type="redirect">${redirectUrl}</result>
        </action>
    


    <action name="registrering" method="showRegisterUserPage" class="com.x.web.action.RegisterAction">
        <result name="registeruserpage" type="tiles">registeruserpage</result>
    </action>

</package>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:javaee="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <javaee:display-name>X</javaee:display-name>
    <context-param>
        <javaee:param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
        </javaee:param-name>
        <javaee:param-value>/WEB-INF/tiles.xml</javaee:param-value>
    </context-param>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <javaee:listener-class>org.apache.struts2.tiles.StrutsTilesListener
        </javaee:listener-class>
    </listener>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

我得到了例外:

org.apache.tiles.TilesException:

ServletException including path '/templates/mainpage.jsp'.

org.apache.tiles.util.TilesIOException: JSPException including path '/content/mainpage/mainpageBody.jsp'.

org.apache.tiles.TilesException: Attribute 'bodybox1' not found.

我做错了什么?

【问题讨论】:

  • 发布 JSP 页面的内容。你用什么版本的插件?
  • 我下班回家后会这样做!
  • 您的配置中没有bodybox1 名称的属性。
  • @AleksandrM 我在 mainpageBody.jsp 的 div 中有 &lt;tiles:insertAttribute name="bodybox1" /&gt;
  • 正是我的观点。您正在尝试插入属性,但您没有声明它。

标签: java xml jsp struts2 tiles


【解决方案1】:

试试这个web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>X</display-name>

    <listener>
        <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>
    <context-param>
        <param-name>tilesDefinitions</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
    </context-param>
        <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

并检查 tiles.xmlWEB-INF 文件夹中。

【讨论】:

  • 我今天回家后会试试这个,如果它有效,请告诉你,谢谢。我的tiles.xml 在web-inf 中是的。
  • 我遇到了同样的问题。
  • 我可能会跳过在这些 div 中包含 JSP 的想法,反正它没有任何区别。如果您知道解决方案,您可以编写它,但不要浪费您的时间。非常感谢您的宝贵时间!
  • 如果你在类路径上有约定插件删除它,重建,重新部署,重新启动。最好把web root的文件夹结构和内容贴出来。
猜你喜欢
  • 1970-01-01
  • 2019-02-06
  • 2019-03-08
  • 1970-01-01
  • 2020-08-25
  • 2013-02-07
  • 2018-06-13
  • 2021-04-09
  • 2021-12-11
相关资源
最近更新 更多