我用jetty9尝试了tile3+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,它们都不起作用!在日志中,有证据表明它解析了瓷砖文件。可以选择struts 2.3.14/2.3.12版本。