STRUTS 2 java.lang.ClassNotFoundException

时间:2016-01-14 16:45:57

标签: java exception configuration struts2

我正在尝试一个简单的helloworld,当我启动服务器时出现以下错误:

SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.filter.ng.StrutsPrepareAndExecuteFilter
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:424)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4076)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4730)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
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)

我的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" 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>LoginStruts2DB</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.filter.ng.StrutsPrepareAndExecuteFilter
      </filter-class>
   </filter>

   <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>
</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" />
   <package name="LoginStruts2DB" extends="struts-default">

      <action name="hello"  class="com.HelloAction.HelloWorldAction" method="execute">
            <result name="success">jsp/HelloWorld.jsp</result>
      </action>
   </package>
</struts>

这是我的书:

enter image description here

知道可能出现什么问题吗?

注意:如果我使用不推荐的:

,代码可以正常工作
org.apache.struts2.dispatcher.FilterDispatcher

1 个答案:

答案 0 :(得分:2)

您正在使用

  

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

the documentation所述,但这是一个错字,正确的FQCN是

  

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

现在已在WW-4543中修复了文档(尽管HTML页面尚未更新)。