tile3 + struts说没有在Jetty中找到定义

时间:2013-05-15 13:40:16

标签: struts2 jetty tiles-3

我使用jetty9尝试了tiles3 + struts / spring mvc几天,它在所有报告无定义错误时都不起作用。我一次又一次地检查了配置。最后我切换到 tomcat以获得相同战争的运气,我就是! Tiles2在jetty9中工作。这是详细信息:

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0" metadata-complete="true">

    <display-name>XX</display-name>


    <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.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
    </listener>

    <session-config>
        <session-timeout>100000</session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file></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.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="default" namespace="/" extends="struts-default">
        <result-types>
            <result-type name="tiles"
                         class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>
        <action name="*Page" method="{1}" class="com.homhon.web.booking.TilesAction">
            <result name="home" type="tiles">home</result>
            <result name="aboutUs" type="tiles">aboutUs</result>
            <result name="contactUs" type="tiles">contactUs</result>
            <result name="registration" type="tiles">registration</result>
        </action>
    </package>
</struts>

tiles.xml文件直接在/ WEB-INF中,tiles3应该使用模式WEB-INF / * / tiles .xml找到此文件夹中的所有文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
        "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
        "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>
    <definition name="baseLayout" template="/WEB-INF/layouts/baseLayout.jsp">
        <put-attribute name="title" value="Template" />
        <put-attribute name="header" value="/WEB-INF/templates/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/templates/menu.jsp" />
        <put-attribute name="body" value="/WEB-INF/templates/body.jsp" />
        <put-attribute name="footer" value="/WEB-INF/templates/footer.jsp" />
    </definition>

    <definition name="home" extends="baseLayout">
        <put-attribute name="title" value="Home Page" />
        <put-attribute name="body" value="/WEB-INF/pages/home.jsp" />
    </definition>
    <definition name="aboutUs" extends="baseLayout">
        <put-attribute name="title" value="About Us Page" />
        <put-attribute name="body" value="/WEB-INF/pages/aboutUs.jsp" />
    </definition>

    <definition name="contactUs" extends="baseLayout">
        <put-attribute name="title" value="Contact Us Page" />
        <put-attribute name="body" value="/WEB-INF/pages/contactUs.jsp" />
    </definition>

    <definition name="registration" extends="baseLayout">
        <put-attribute name="title" value="Register Here" />
        <put-attribute name="body" value="/WEB-INF/pages/registration.jsp" />
    </definition>
</tiles-definitions>

日志显示:

2094 [main] DEBUG o.apache.commons.digester.Digester - register('-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN', 'jar:file:/XXX/jetty-0.0.0.0-8080-web.war-_web-any-/webapp/WEB-INF/lib/tiles-core-3.0.0.jar!/org/apache/tiles/resources/tiles-config_3_0.dtd'
2094 [main] DEBUG o.apache.commons.digester.Digester - register('-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN', 'jar:file:/XXX/jetty-0.0.0.0-8080-web.war-_web-any-/webapp/WEB-INF/lib/tiles-compat-3.0.0.jar!/org/apache/tiles/compat/resources/tiles-config_2_0.dtd'
2094 [main] DEBUG o.apache.commons.digester.Digester - register('-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN', 'jar:file:/XXX/jetty-0.0.0.0-8080-web.war-_web-any-/webapp/WEB-INF/lib/tiles-compat-3.0.0.jar!/org/apache/tiles/compat/resources/tiles-config_2_1.dtd'
2094 [main] DEBUG o.apache.commons.digester.Digester - register('-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN', 'jar:file:/XXX/jetty-0.0.0.0-8080-web.war-_web-any-/webapp/WEB-INF/lib/tiles-compat-3.0.0.jar!/org/apache/tiles/compat/resources/tiles-config_1_1.dtd'
2094 [main] DEBUG o.apache.commons.digester.Digester - register('-//Apache Software Foundation//DTD Tiles Configuration 1.3//EN', 'jar:file:/XXX/jetty-0.0.0.0-8080-web.war-_web-any-/webapp/WEB-INF/lib/tiles-compat-3.0.0.jar!/org/apache/tiles/compat/resources/tiles-config_1_3.dtd'
2094 [main] DEBUG o.apache.commons.digester.Digester - register('-//Apache Software Foundation//DTD Tiles Configuration 1.4//EN', 'jar:file:/XXX/jetty-0.0.0.0-8080-web.war-_web-any-/webapp/WEB-INF/lib/tiles-compat-3.0.0.jar!/org/apache/tiles/compat/resources/tiles-config_1_4.dtd'
2125 [main] DEBUG o.s.c.i.s.PathMatchingResourcePatternResolver - Resolved location pattern [/WEB-INF/**/tiles*.xml] to resources [ServletContext resource [/WEB-INF/tiles.xml]]

org.apache.tiles.definition.NoSuchDefinitionException: Cannot find definition named 'home'
    at org.apache.tiles.impl.mgmt.CachingTilesContainer.render(CachingTilesContainer.java:123) ~[tiles-core-3.0.0.jar:3.0.0]
    at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:71) ~[struts2-tiles3-plugin-2.3.12.jar:2.3.12]
    at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186) ~[struts2-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275) ~[xwork-core-2.3.12.jar:2.3.12]
    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) ~[struts2-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) ~[xwork-core-2.3.12.jar:2.3.12]
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) ~[struts2-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) ~[xwork-core-2.3.12.jar:2.3.12]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.12.jar:2.3.12]

这适用于Tomcat 7.0。但我尝试了jetty9和jetty8,它们都没有用!在日志中,有证据显示它已解析了tile文件。您可以选择struts版本2.3.14 / 2.3.12。

1 个答案:

答案 0 :(得分:0)

这有点旧,但您可以尝试更改以下内容....

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

....对此:

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