org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuterFilter not found

Struts2报错


如标题所述,配置Struts2.3时报了这样的错误,踩了挺多坑的

解决办法

(1)网上最流行的解法是说:Struts2.5版本的web.xml配置中应该这样写:
在这里插入图片描述
而2.3是:

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

可是,我的Struts就是2.3的,查找后也确实存在该路径,最便捷的查找路径的办法,按ctrl点击filter-class中的类路径。

(2)上述方法不管用,考虑的是jar包冲突,因为自己除了引入Struts2的jar包,还引入了servlet-api即其他jsp相关的jar包。可能和自带的jar包有冲突了,于是删除了自己引入的jar包,但是还是没有卵用。

(3)[郁闷…]既然2.3不行,于是升级为2.5,在2.5中,log4j-api是要的,而之前版本的xwork已经被并到Struts-core包中了。升级完后,把原来的项目移除Tomcat后重新添加——运行,还是报错,只不过没了ng。

(4)重新审视我的配置文件,查找是否为配置文件的问题:配置都很简单,没有骚操作。其中action的类名和方法名也没有问题,然后确认Tomcat是否真的加载了文件,在Tomcat的项目的classes目录下进行查找,发现是有的。

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-
//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="user" namespace="/"  extends="struts-default">
        <action name="user_login_go" class="com.fang.service.UserAction" method="user_login">
            <result name="success">/userlogin.jsp</result>
        </action>
    </package>
</struts> 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-
//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
    <display-name>Struts2 Web Application</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

(5)确认Apache Tomcat的环境中添加了这些jar包,其实就是将jar包引入到webapp(myEclipse叫webRoot)目录下的lib目录中,因为我是采用Maven的,直接右击项目,属性(properties),搜索Deployment,点击add将Maven引入到工程下,终于成功解决。

原来,eclipse中使用tomcat使用启动web项目的流程是 java build path编译项目源代码生成的class文件放到buildpath的设置路径中,根据web deployment assembly将项目中的各个资源发布到设置的指定文件中,此时没有引入相关jar包,所以报了这个错。
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
struts 2.3.4.1 最新英文版API =========================================================== 概览 程序包 类 使用 树 已过时 索引 帮助 上一个 下一个 框架 无框架 所有类 ----------------------------------------------------------- Struts 2.3.4.1 API 程序包 程序包 说明 ------------------------------------------------------------ com.opensymphony.xwork2 Main XWork interfaces and classes. com.opensymphony.xwork2.config Configuration core classes. com.opensymphony.xwork2.config.entities Configuration entity classes. com.opensymphony.xwork2.config.impl Configuration implementation classes. com.opensymphony.xwork2.config.providers Configuration provider classes. com.opensymphony.xwork2.conversion com.opensymphony.xwork2.conversion.annotations Type conversion annotations. com.opensymphony.xwork2.conversion.impl com.opensymphony.xwork2.conversion.metadata Type conversion meta data classes. com.opensymphony.xwork2.inject Guice (pronounced "juice"). com.opensymphony.xwork2.inject.util Guice util classes. com.opensymphony.xwork2.interceptor Interceptor classes. com.opensymphony.xwork2.interceptor.annotations Interceptor annotations. com.opensymphony.xwork2.mock XWork specific mock classes. com.opensymphony.xwork2.ognl com.opensymphony.xwork2.ognl.accessor com.opensymphony.xwork2.spring Spring ObjectFactory classes. com.opensymphony.xwork2.spring.interceptor Spring specific interceptor classes. com.opensymphony.xwork2.test com.opensymphony.xwork2.util XWork util classes. com.opensymphony.xwork2.util.classloader com.opensymphony.xwork2.util.finder com.opensymphony.xwork2.util.fs com.opensymphony.xwork2.util.location Classes and utilities used to track location information. com.opensymphony.xwork2.util.logging com.opensymphony.xwork2.util.logging.commons com.opensymphony.xwork2.util.logging.jdk com.opensymphony.xwork2.util.profiling Classes to enable profiling of action execution. com.opensymphony.xwork2.util.reflection com.opensymphony.xwork2.validator XWork validation subsystem. com.opensymphony.xwork2.validator.annotations Validator annotations. com.opensymphony.xwork2.validator.metadata Validator meta data classes. com.opensymphony.xwork2.validator.validators XWork default validator classes. org.apache.struts2 org.apache.struts2.components org.apache.struts2.components.template org.apache.struts2.config Classes for Struts configuration and property handling. org.apache.struts2.dispatcher Classes for action dispatching in Struts (the Controller part of MVC). org.apache.struts2.dispatcher.mapper org.apache.struts2.dispatcher.multipart Classes to help dispatch multipart HTTP requests. org.apache.struts2.dispatcher.ng This package contains a reimagining of the traditional Struts filter dispatchers. org.apache.struts2.dispatcher.ng.filter org.apache.struts2.dispatcher.ng.listener org.apache.struts2.dispatcher.ng.servlet org.apache.struts2.impl org.apache.struts2.interceptor org.apache.struts2.interceptor.debugging org.apache.struts2.interceptor.validation org.apache.struts2.servlet.interceptor org.apache.struts2.util org.apache.struts2.views org.apache.struts2.views.annotations org.apache.struts2.views.freemarker org.apache.struts2.views.freemarker.tags org.apache.struts2.views.jsp Struts's JSP tag library. org.apache.struts2.views.jsp.iterator org.apache.struts2.views.jsp.ui org.apache.struts2.views.util Miscellaneous helper classes for all views. org.apache.struts2.views.velocity Classes for views using Velocity. org.apache.struts2.views.velocity.components org.apache.struts2.views.xslt The new xslt view supports an extensible Java XML adapter framework that makes it easy to customize the XML rendering of objects and to incorporate structured XML text and arbitarary DOM fragments into the output. ------------------------------------------------------------ 概览 程序包 类 使用 树 已过时 索引 帮助

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

legendaryhaha

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值