开发者

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

I am trying to make a small login application in struts 2. My 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;
    }
}

And i have added these libraries to my project:

  • commons-logging-1.0.4.jar
  • struts2-core-2.1.8.1.jar
  • ognl-2.6.11.jar
  • xwork-2.1.0.jar
  • freemarker-2.3.9.jar

When I try to run this on Tomcat 6 I got following error:

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


Make sure the following are on your class path:

  • commons-fileupload-X.X.X.jar
  • commons-io-X.X.X.jar
  • commons-logging-X.X.X.jar
  • commons-logging-api.X.X.jar
  • freemarker-X.X.X.jar
  • ognl-X.X.X.jar
  • struts2-core-X.X.X.X.jar
  • xwork-core-X.X.X.jar
  • javassist-3.7.ga.jar (new for Struts versions 2.2.1 and higher)
  • commons-lang3-x.x

Edit: Have you followed https://struts.apache.org/getting-started/how-to-create-a-struts2-web-application.html to set up your project?

Try:

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


You need to add one more jar commons-lang3-x.x

scroll down to the end of apache logs you can find 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


I had the same problem. I solved it this way: 1st I deleted all my added libs. Then I added them via Project->Properties->Deployment Assembly. Before, I just copied them into the WEB-INF/lib folder. That doesn't seem to work all the time. hope this helps.


add commons-lang3- jar file to WEB-INF\lib folder.


just add commons-lang3XXXX.jar to your library


If you are using Struts2 version 2.5 you need to change from org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter to org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter. See:

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


I got this error too and I checked my dtd in web.xml and I changed the version from 2.4 to 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">


I suggest doing a Maven build, the dependencies will be resolved by Maven. This is what I had to put in 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>


It seems, commons-lang3-XXX.jar file is missing in your class path. You can resolve it by adding the jar to your lib folder.


Regarding the error:

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

PROBLEM:

There seems to be a problem with the following combination Eclipse - WTPPlugin - Struts2 - Maven3

FINDINGS:

We assume that when we run a project as "Run on server" we assume that eclipse runs maven, created WAR file and deploys on the server. But its not working perfectly for me. I do see the WAR file in the target folder where maven creates WAR, and the WAR is perfect. But eclipse seems to run something else.

SOLUTION:

Put all the required JAR files into eclipse project's WEB-INF/lib. If you are using version control, make sure to ignore the lib folder. How to find all the required JARs when you are using maven? Go to target folder and the WAR file. Burst it open and go to WEB-INF/lib. Copy all these JARS to eclipse project's WEB-INF/lib.


Got similar problem while starting strut2 project.

I was using the latest jars. Web.xml has version 3.0. And it does not contains the proper dispatcher in its configuration. I added the correct dispatcher filter i.e.

org.apache.struts2.dispatcher.FilterDispatcher 

instead of

org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 

or

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

it worked greatly.


A struts.action.excludePattern constant setting caused to me the same trouble now. I didn't got any explanation, not even a stack trace as you, only a pure "error FilterStart". I tracked this by reverting to the previous versions of the code and checked, what changed.


Being new to the Struts2 framework, I recently came across the same (or very similar) error. In my case I was using annotations within the Action class rather than the struts.xml file.

For example

@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() { ... }

However when I changed the action value to include the *.action extension (see below) Struts would throw the "SEVERE: Exception starting filter struts2" error noted above.

@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() { ... }

The cause of this error wasn't obvious as it didn't manifest itself immediately. Looking through the Tomcat localhost..log file I found the stacktrace for the error and was able to remedy the issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜