SEVERE:异常启动过滤器struts2 java.lang.ClassNotFoundException:org.apache.struts2.dispatcher.FilterDispatcher

时间:2011-03-10 08:02:58

标签: java struts2

我正在尝试在struts 2中创建一个小型登录应用程序。我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

    <display-name>StrutsPrj</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>Login.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

struts.xml中:

<struts>
    <package name="default" extends="struts-default" namespace="/">
        <action name="login" method="execute"
            class="struts2.LoginAction">
            <result name="success">Welcome.jsp</result>
            <result name="error">Login.jsp</result>
        </action>
    </package>
</struts>    

的login.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Screen - Struts 2</title>
</head>
<body>

<s:actionerror />
    <s:form action="login.action" method="post">
        <s:textfield name="username" value="UserName" size="20" />
        <s:password name="password" value="Password" size="20" />
        <s:submit method="execute" value="Login" align="center" />
    </s:form>
</body>
</html>

Welcome.jsp中:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Screen - Struts 2</title>
</head>
<body>
<h2>Congrates, <s:property value="username" />...!</h2>
</body>
</html>

LoginAction.java:

package struts2;

public class LoginAction {
    private String username;
    private String password;

    public String execute() {
        if (this.username.equals("admin")
            && this.password.equals("admin123")) {
            return "success";
        } else {
        return "error";
        }
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

我已将这些库添加到我的项目中:

  • 共享记录-1.0.4.jar
  • struts2的核 - 2.1.8.1.jar
  • OGNL-2.6.11.jar
  • XWork的-2.1.0.jar
  • 的freemarker-2.3.9.jar

当我尝试在Tomcat 6上运行它时出现以下错误:

Mar 10, 2011 1:17:59 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Java/jre6/bin/client;C:/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Java\jdk1.5\bin\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Liquid Technologies\Liquid XML Studio 2009\XmlDataBinder7\Redist7\cpp\win32\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\MySQL\MySQL Server 5.0\bin
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:newPrj' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsPrj' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
Mar 10, 2011 1:18:00 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Mar 10, 2011 1:18:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2037 ms
Mar 10, 2011 1:18:00 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Mar 10, 2011 1:18:00 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:269)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/StrutsPrj] startup failed due to previous errors
Mar 10, 2011 1:18:01 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 10, 2011 1:18:01 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 10, 2011 1:18:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/97  config=null
Mar 10, 2011 1:18:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1756 ms

13 个答案:

答案 0 :(得分:20)

确保您的班级路径上有以下内容:

  • 公地文件上传-X.X.X.jar
  • 公地-IO-X.X.X.jar
  • 共享记录-X.X.X.jar
  • 共享记录-api.X.X.jar
  • 的freemarker-X.X.X.jar
  • OGNL-X.X.X.jar
  • struts2的核 - X.X.X.X.jar
  • XWork的核 - X.X.X.jar
  • javassist-3.7.ga.jar(Struts 2.2.1及更高版本的新增功能)
  • 公地lang3-x.x中

编辑:您是否按照http://struts.apache.org/release/2.3.x/docs/how-to-create-a-struts-2-web-application.html设置了项目?你为什么使用struts 2.1.X.X而不是2.2.x.x?

尝试:

        <filter>
            <filter-name>action</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>action</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

答案 1 :(得分:13)

您需要再添加一个jar commons-lang3-x.x

向下滚动到apache日志的末尾,你可以找到ClassNotFoundException: org.apache.commons.lang3.StringUtils

Caused by: java.lang.ClassNotFoundException: **org.apache.commons.lang3.StringUtils**
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
... 55 more

答案 2 :(得分:4)

我遇到了同样的问题。我这样解决了: 我删除了所有添加的 libs 。然后我通过添加它们 Project->Properties->Deployment Assembly。 以前,我只是将它们复制到WEB-INF/lib文件夹中。这似乎并不总是有效。 希望这有帮助。

答案 3 :(得分:1)

我也收到了此错误,我在dtd中检查了web.xml,并将版本从2.4更改为2.5。

    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" 
version="2.5">

答案 4 :(得分:1)

将commons-lang3-jar文件添加到WEB-INF \ lib文件夹。

答案 5 :(得分:1)

只需将commons-lang3XXXX.jar添加到您的库中

答案 6 :(得分:0)

我建议做一个Maven构建,依赖关系将由Maven解决。 这是我必须放在pom.xml中的内容

     <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.1.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

答案 7 :(得分:0)

struts.action.excludePattern常量设置给我带来了同样的麻烦。我没有得到任何解释,甚至没有像你一样的堆栈跟踪,只有一个纯粹的“错误FilterStart”。我通过恢复到以前版本的代码来跟踪这一点并检查,发生了什么变化。

答案 8 :(得分:0)

关于错误:

SEVERE: Exception starting filter struts2 java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

问题:

以下组合似乎存在问题 Eclipse - WTPPlugin - Struts2 - Maven3

结果:

我们假设当我们以“在服务器上运行”运行项目时,我们假设eclipse运行maven,创建WAR文件并在服务器上部署。但它不适合我。我确实在maven创建WAR的目标文件夹中看到了WAR文件,而WAR是完美的。但是eclipse似乎还有别的东西。

解决方案:

将所有必需的JAR文件放入eclipse项目的WEB-INF / lib中。 如果您使用的是版本控制,请确保忽略lib文件夹。 如何在使用maven时找到所有必需的JAR?转到目标文件夹和WAR文件。将其打开并转到WEB-INF / lib。将所有这些JARS复制到eclipse项目的WEB-INF / lib。

答案 9 :(得分:0)

看来,类路径中缺少commons-lang3-XXX.jar文件。您可以通过将jar添加到lib文件夹来解决它。

答案 10 :(得分:0)

如果您使用的是Struts2版本2.5,则需要将 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 更改为 org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 即可。参见:

java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter in web.xml

答案 11 :(得分:0)

启动strut2项目时出现类似问题。

我正在使用最新的罐子。 Web.xml的版本为3.0。并且它的配置中不包含适当的调度程序。我添加了正确的调度程序过滤器,即

org.apache.struts2.dispatcher.FilterDispatcher 

而不是

org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter. 

它起了很大的作用。

答案 12 :(得分:-1)

作为Struts2框架的新手,我最近遇到了相同(或非常相似)的错误。在我的例子中,我在Action类中使用注释而不是struts.xml文件。

例如

@Action(value="/jsp/edit-file",
   results={@Result(name="success",location="/jsp/edit-success.jsp"),
            @Result(name="failure",location="/jsp/edit-failure.jsp")})
public String execute() { ... }

然而,当我更改动作值以包含* .action扩展(见下文)时,Struts将抛出上面提到的“SEVERE:异常启动过滤器struts2”错误。

@Action(value="/jsp/edit-file.action",
   results={@Result(name="success",location="/jsp/edit-success.jsp"),
            @Result(name="failure",location="/jsp/edit-failure.jsp")})
public String execute() { ... }

此错误的原因并不明显,因为它没有立即显现出来。通过Tomcat localhost..log文件,我找到了错误的堆栈跟踪,并且能够解决问题。