Tomcat 10寻找javax.servlet.Filter但仅存jakarta.servlet.Filter的问题求助
Struts 2.5 + Tomcat 10.0 运行报错:
javax.servlet.Filter 类找不到 java.lang.NoClassDefFoundError: javax/servlet/Filter
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
问题核心:Tomcat 10.0 尝试加载
javax.servlet.Filter,但项目中仅存在jakarta.servlet.Filter
Tomcat 版本:10.0 Struts 版本:2.5
以下是项目相关信息与文件内容:
项目依赖与结构
- Jakarta 类库截图:

- 项目结构截图:

struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <package name="first" extends="struts-default"> <action name="Action" class="guild.Action"> <result name="success">/success.jsp</result> <result name="error">/error.jsp</result> </action> </package> </struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="5.0"> <display-name>FSGuild</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.jsp</welcome-file> <welcome-file>default.htm</welcome-file> </welcome-file-list> <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>
Action.java
package guild; public class Action { public String execute() { System.out.println("Someone called execute"); return "SUCCESS"; } }
error.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Error</title> </head> <body> <h1>ERROR</h1> </body> </html>
success.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>SUCCESS</title> </head> <body> <h1>SUCCESS</h1> </body> </html>
内容的提问来源于stack exchange,提问作者Anubhav Sharma
相关产品推荐
相关产品推荐

