Struts 1到Struts2升级 - 配置Tiles的问题

时间:2015-12-21 19:13:35

标签: struts2 apache-tiles

我正在配置Struts应用程序以在Struts2上运行,但是tile在部署时出现以下错误:

目标状态:在Server AdminServer上部署失败 java.lang.ClassNotFoundException:org.apache.tiles.web.startup.TilesListener

目前,我只想提出登录页面。

以下是我的配置文件:

的web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>

<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">

  <!-- Filter Configuration  -->
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>  
  <listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
  </listener>
  <context-param>
        <param-name>tilesDefinitions</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
  </context-param>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- Action Servlet Configuration  -->
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
   <init-param>
       <param-name>config</param-name>
       <param-value>/WEB-INF/struts-config.xml</param-value>
   </init-param>
   <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
   </init-param>
   <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
   </init-param>
   <init-param>
       <param-name>validate</param-name>
       <param-value>true</param-value>
   </init-param>
  <load-on-startup>1</load-on-startup>
       <run-as>
    <role-name>WARP_InternalApplications</role-name>
    </run-as> 
  </servlet>

  <!-- Action Servlet Mapping -->
  <servlet-mapping>
  <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <session-config>
       <session-timeout>30</session-timeout>
  </session-config>

  <!-- The Welcome File List -->
  <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <error-page>
      <error-code>500</error-code>
      <location>/Error500.jsp</location>
  </error-page>

  <error-page>
      <error-code>404</error-code>
      <location>/Error404.jsp</location>
  </error-page>


    <!-- Tag Library Descriptor -->
    <jsp-config>
<taglib>
    <taglib-uri>/WEB-INF/tlds/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>/WEB-INF/tlds/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>/WEB-INF/tlds/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>/WEB-INF/tlds/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>/WEB-INF/tlds/application.tld</taglib-uri>
    <taglib-location>/WEB-INF/tlds/application.tld</taglib-location>
</taglib>
   </jsp-config>

    <security-role>
     <role-name>WARP_InternalApplications</role-name>
    </security-role>
    <security-role>
     <role-name>resource</role-name>
    </security-role>

  </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>
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />


<package name="default"  extends="struts-default">
    <result-types>
        <result-type name="tiles"
            class="org.apache.struts2.views.tiles.TilesResult" />
    </result-types>
    <action name="login"
        class="com.abc.xxxx.action.LoginAction">
        <result name="success">/MainPage.action</result>
    </action>
    <action name="MainPage">
        <result type="tiles">XXXX.welcome.page.layout</result>
    </action>   
</package>

</struts>

tiles.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” &GT;

<tiles-definitions>
<definition name="XXXX.login.layout" template="/XXXX_login.jsp">
    <put-attribute name="header" value="XXXX_header_noLO.jsp" />
    <put-attribute name="body_content" value="XXXX_loginBody.jsp"/>
    <put-attribute name="title" value="Login"/>
    <put-attribute name="footer" value="XXXX_footer.jsp" />     
</definition>

<definition name="XXXX.error404.page.layout" extends="XXXX.login.layout">
    <put-attribute name="body_content" value="XXXX_errorBody.jsp"/>
    <put-attribute name="title" value="Error 404"/>
</definition>
<definition name="XXXX.error500.page.layout" extends="WIFE.login.layout">
    <put-attribute name="body_content" value="XXXX_errorBody.jsp"/>
    <put-attribute name="title" value="Error 500"/>
</definition>

</tiles-definitions>

的index.jsp:

 <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
 <tiles:insertDefinition name="XXXX.login.layout"/>

以下是我在WEB-INF / lib下用于struts2的jar:

 <include name="commons-beanutils-1.8.0.jar"/>
 <include name="commons-collections-3.1.jar"/>
 <include name="commons-digester-2.0.jar"/>
 <include name="commons-fileupload-1.2.2.jar"/>
 <include name="commons-io-2.0.1.jar"/>
 <include name="commons-lang3-3.1.jar"/>
 <include name="commons-logging-1.1.1.jar"/>    
 <include name="commons-logging-api-1.1.jar"/>
 <include name="commons-validator-1.3.1.jar"/>          
 <include name="freemaker-2.3.19.jar"/>
 <include name="javassist-3.11.0.GA.jar"/>
 <include name="ognl-3.0.5.jar"/>
 <include name="struts2-tiles-plugin-2.3.4.jar"/>
 <include name="tiles-api-2.0.6.jar"/>
 <include name="tiles-core-2.0.6.jar"/>
 <include name="tiles-jsp-2.0.6.jar"/>
 <include name="xwork-core-2.3.4.jar"/> 

1 个答案:

答案 0 :(得分:0)

请尝试包含tiles-srvlet jar。 TilesListener类存在于该jar上,如图2.2所示。