IDEA中web项目使用struts2出错——java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
这几天在学javaWeb开发 使用SSH中的struts2框架时 每次配置过web.xml文件中的过滤器的时候总是会报一个org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter的错误 一开始以为是代码的问题 反复检查之后发现没错 之后以为是tomcat的问题 修改了tomcat配置之后还是出错 后来确定是struts2的问题
解决方法 :
自己到官网上面去下载struts2的安装包
[附上struts2官网传送门](http://struts.apache.org/)
点进去之后是这个亚子
点击download 下载最新版的就可以
下载好之后解压
新建项目 选择web项目
笔者目前用的是struts2.5.16 配置代码应该是org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
最后打开File ——> Project Structure ——> Problems
点fix 再点添加那个选项
问题得到解决 过滤器正常允许 服务器正常启动