2011-10-04 50 views
2

我使用的是struts 2.2.1和tiles 2.2.2。我做每一个步骤描述here,但我不能让瓷砖工作...我得到,同时部署了以下错误我的战争GlassFish的3.1:Tiles与Struts2搭配使用的问题

[#|2011-10-04T08:43:28.117+0200|SEVERE|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=74;_ThreadName=AutoDeployer;|Exception while invoking class com.sun.enterprise.web.WebApplication start method 
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.struts2.tiles.StrutsTilesListener 
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:130) 

在我的WEB-INF/lib中我有commons- collections-3.1.jar,commons-fileupload-1.2.1.jar,struts2-core-2.2.1.jar,tiles-api-2.2.2.jar,tiles-core-2.2.2.jar,tiles-jsp- 2.2.2.jar和xwork-core-2.2.1.jar。

这是我的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" /> 

    <package name="basicstruts2" extends="struts-default"> 
     <interceptors> 
      <interceptor-stack name="appDefault"> 
       <interceptor-ref name="defaultStack"> 
        <param name="exception.logEnabled">true</param> 
        <param name="exception.logLevel">ERROR</param> 
       </interceptor-ref> 
      </interceptor-stack> 
     </interceptors> 

     <default-interceptor-ref name="appDefault" /> 

     <result-types> 
      <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" /> 
     </result-types> 

     <global-results> 
      <result name="exception">/jsp/exceptions/exception.jsp</result> 
      <result name="webServiceException">/jsp/exceptions/webserviceexception.jsp</result> 
     </global-results> 

     <global-exception-mappings> 
     <exception-mapping exception="java.lang.Exception" result="exception" /> 
     <exception-mapping exception="java.io.IOException" result="exception" /> 
     <exception-mapping exception="exceptions.WebServiceExceptionForStruts" 
       result="webServiceException" /> 
     </global-exception-mappings> 

     <action name="tilesTest" class="test.action.TilesTest"> 
      <result name="success" type="tiles">/welcome.tiles</result> 
     </action> 

     <action name="index"> 
      <result>/jsp/index.jsp</result> 
     </action> 

    </package> 
</struts> 

插入代码到我的struts.xml后,我在日食出现此错误:

enter image description here

这是我的网页。 xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" 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"> 
    <display-name>Consumer</display-name> 

    <welcome-file-list> 
     <welcome-file>/jsp/index.jsp</welcome-file> 
    </welcome-file-list> 

    <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.struts2.tiles.StrutsTilesListener</listener-class> 
    </listener> 
    <context-param> 
     <param-name>tilesDefinitions</param-name> 
     <param-value>/WEB-INF/tiles.xml</param-value> 

    </context-param> 

</web-app> 

非常感谢!

回答

1

您错过了S2 tiles插件。它在参考文章中列出。

您的第二个XML问题在IDE错误中有明确说明;错误消息中给出的元素顺序不是您在XML文件中定义元素的顺序。

+0

我已经添加了Struts2的瓷砖,插件-2.2.1.jar和纠正在struts.xml中的顺序。 IDE错误消失了,但ClassDefNotFound仍然存在(现在在另一个点):[#| 2011-10-04T23:39:35.690 + 0200 | SEVERE | glassfish3.1 | org.apache.catalina.core.ContainerBase | _ThreadID = 17; _ThreadName = AutoDeployer; | ContainerBase.addChild:start: org.apache.catalina.LifecycleException:java.lang.IllegalArgumentException:java.lang.NoClassDefFoundError:org/apache/tiles/web/startup/TilesListener \t在org.apache.catalina.core.StandardContext.start(StandardContext.java:5271) – strauberry

+0

我的第一个假设是要实际检查[tiles tiles插件使用的tiles版本](http://mvnrepository.com/artifact/ org.apache.struts/Struts2的瓷砖,插件/ 2.2.1)。这会让我相信你是混合和匹配不兼容的版本。 –

+0

好的一个:-)依赖关系是“邪恶的一部分”。但是有很多依赖......我会看看maven ^^非常感谢您的帮助! – strauberry

0

ClassNotFoundException,看起来像缺少jar问题。你能看到正在部署在glassfish server上的战争中的tiles plugin jar。如果没有检查在你的IDE中检查战争创建设置。我们在不把瓶子从自由战争推向战争时遇到了这个问题。

+0

在自动部署文件夹中的战争也有我所定义的所有罐子...... – strauberry

0

ClassNotFoundException总是提醒您某些引用的类/ jar已丢失。确保你有瓷砖所需的所有基本罐子。

在我的情况下,我在我的struts2应用程序中使用这些jar(除了struts2 jars)来测试演示磁贴项目。

  • 公地的BeanUtils-1.7.0.jar
  • 公共沼气池-2.0.jar
  • 共享记录-1.1.1.jar
  • 共享记录-API-1.1.jar
  • OGNL-3.0.1.jar
  • SLF4J-API-1.6.2.jar
  • SLF4J-简单1.6.2.jar
  • Struts2的瓷砖 - 插件 - 2.2.3.1.jar
  • 瓷砖-API-2.2.2.jar
  • 瓷砖-COMPAT-2.2.2.jar
  • 瓷砖核-2.2.2.jar
  • 瓷砖-JSP-2.2.2.jar
  • 瓷砖-的servlet-2.2.2.jar
  • 瓷砖,模板2.2.2.jar

好运。

问候, 阿米尔·阿里·