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

后端 未结 13 580
一生所求
一生所求 2020-12-16 00:56

I am trying to make a small login application in struts 2. My web.xml:



        
相关标签:
13条回答
  • 2020-12-16 01:07

    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>
    
    0 讨论(0)
  • 2020-12-16 01:07

    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.

    0 讨论(0)
  • 2020-12-16 01:10

    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

    0 讨论(0)
  • 2020-12-16 01:10

    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 讨论(0)
  • 2020-12-16 01:11

    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.

    0 讨论(0)
  • 2020-12-16 01:14

    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 http://struts.apache.org/release/2.3.x/docs/how-to-create-a-struts-2-web-application.html to set up your project? Why are you using struts 2.1.X.X and not 2.2.x.x?

    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>
    
    0 讨论(0)
提交回复
热议问题