0

我正在尝试将 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>
4

3 回答 3

2

要将 Tiles 3 与 Struts 2 集成,您需要使用struts2- tiles3 - plugin,而不是struts2- tiles -plugin

您正在使用Tiles2 监听器

<listener-class>
    org.apache.struts2.tiles.StrutsTilesListener
</listener-class>

右边的是Tiles3 监听器

<listener-class>
    org.apache.tiles.extras.complete.CompleteAutoloadTilesListener
</listener-class>

您还使用了错误的Struts2 Filter

<filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter
</filter-class>

使用完整的:

<filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
于 2015-08-05T06:00:02.497 回答
0

看起来你错过了struts2-tiles-plugin.jar你的类路径。添加它,错误应该消失了。

于 2015-08-05T05:16:29.537 回答
0

我的猜测是您缺少具有org.apache.struts2.tiles.StrutsTilesListener类的 jar/依赖项,即struts2-tiles-pluginjar。只需查看search.maven.org

如果要下载 jar,请从同一链接下载。

如果您使用的是 maven,请添加此依赖项。

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-tiles-plugin</artifactId>
    <version>2.5-BETA1</version>
</dependency>
于 2015-08-05T05:22:06.703 回答