0

Struts 2 を学んでおり、タイル プラグインに関するデモを作成しようとしています。そして、私は上記の例外を得ました。org.apache.tiles.TilesException: Attribute 'header' not found in struts2で同じトピックを見つけましたが、役に立ちません。これが私のコードです:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts 2 Basic 2</display-name>
    
    <context-param>
        <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</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>
    
    <listener>
        <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>baselayout.jsp</welcome-file>
    </welcome-file-list>

</web-app>

struts.xml

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

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>

        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>

        
    </package>

    <!-- Add packages here -->

</struts>

tiles.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "unknown.dtd">
<tiles-definitions>
    <definition name="baseLayout" template="/baselayout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/header.jsp"/>
        <put-attribute name="left" value="/leftmenu.jsp" />
        <put-attribute name="footer" value="/footer.jsp" />
    </definition>
    <definition name="validateView" extends="baseLayout">
        <put-attribute name="right" value="/validatedemo.jsp" />
        <put-attribute name="title" value="Validate Demo" />
    </definition>
    <definition name="interceptorView" extends="baseLayout">
        <put-attribute name="right" value="/interceptordemo.jsp" />
        <put-attribute name="title" value="Interceptor Demo" />
    </definition>
    <definition name="valuestackView" extends="baseLayout">
        <put-attribute name="right" value="/valuestackdemo.jsp" />
        <put-attribute name="title" value="ValueStack Demo" />
    </definition>
</tiles-definitions>

baselayout.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
    <table border="1" cellpadding="2" align="center">
        <tr>
            <td colspan="2" height="30"><tiles:insertAttribute name="header" /></td>
        </tr>
        <tr>
            <td width="30%"><tiles:insertAttribute name="left" /></td>
            <td width="70%"><tiles:insertAttribute name="right" /></td>
        </tr>
        <tr>
            <td colspan="2" height="30"><tiles:insertAttribute name="footer" /></td>
        </tr>
    </table>
</body>
</html>

例外

INFO: Server startup in 1833 ms
Oct 16, 2013 12:21:21 AM org.apache.jasper.compiler.TldLocationsCache tldScanJar
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Oct 16, 2013 12:21:22 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Struts2Basic2] threw exception [javax.servlet.ServletException: javax.servlet.jsp.JspException: Error executing tag: Attribute 'header' not found.] with root cause
org.apache.tiles.TilesException: Attribute 'header' not found.
    at org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:112)
    at org.apache.tiles.jsp.taglib.RenderTagSupport.execute(RenderTagSupport.java:154)
    at org.apache.tiles.jsp.taglib.RoleSecurityTagSupport.doEndTag(RoleSecurityTagSupport.java:75)
    at org.apache.tiles.jsp.taglib.ContainerTagSupport.doEndTag(ContainerTagSupport.java:80)
    at org.apache.jsp.baselayout_jsp._jspx_meth_tiles_005finsertAttribute_005f1(baselayout_jsp.java:152)
    at org.apache.jsp.baselayout_jsp._jspService(baselayout_jsp.java:84)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

そしてプロジェクト(白紙戦争からプロジェクトを作成したので、多くのjarがあります) パッケージ エクスプローラー

PS: 私は最新の struts 2 を使用しており、jar には struts 2 パッケージが付属しています。

4

1 に答える 1

0

あなたが行方不明です

<tiles:insertAttribute name="header" />

baselayout.jsp で

于 2013-10-15T17:57:25.117 に答える