我正在尝试将 Tiles 3 与 Struts 2 集成。
我想我已经在 lib 中添加了所有必要的 jar 文件,但我得到了:
java.lang.ClassNotFoundException: org.apache.struts2.tiles.StrutsTilesListener
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">
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<display-name>My Application</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
瓦片.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/baseLayout.jsp">
<put-attribute name="title" value="MyProject"></put-attribute>
<put-attribute name="header" value=""></put-attribute>
<put-attribute name="body" value=""></put-attribute>
<put-attribute name="menu" value=""></put-attribute>
<put-attribute name="footer" value=""></put-attribute>
</definition>
<definition name="homePageLayout" template="/homePageLayout.jsp">
<put-attribute name="title" value="MyProject-HomePage"></put-attribute>
<put-attribute name="header" value=""></put-attribute>
<put-attribute name="leftMenu" value=""></put-attribute>
<put-attribute name="body" value=""></put-attribute>
<put-attribute name="rightMenu" value=""></put-attribute>
</definition>
</tiles-definitions>
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>
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
<constant name="struts.custom.i18n.resources" value="ApplicationResource"></constant>
<package name="default" namespace="/" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types>
<default-action-ref name="index"/>
<action name="ShowLogin"><result>login.jsp</result></action>
<action name="Login" class="com.myproject.action.Login">
<result name="success">login.jsp</result>
</action>
</package>
</struts>