自从迁移到Java 17和Sping Boot 3后,我一直遇到JSP问题。我知道我们需要使用jakarta.*
而不是javax.*
,但我遗漏了什么吗?我使用的是Spring Tools 4,只是使用JSP运行一个基本的Web应用程序。使用以下依赖项时
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
</dependency>
项目运行,但出现以下错误
The superclass "javax.servlet.http.HttpServlet", determined from the Dynamic Web Module facet version (2.5), was not found on the Java Build Path
我可以通过添加javaxservlet依赖项来消除它
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
但这与在Sping Boot 3中使用javax.*
依赖项是相悖的。
我已经阅读了这些文章,并尝试添加jakarta.servlet.jsp
依赖项,但没有成功。
https://debugah.com/solved-tomcat10-error-jakarta-servlet-servletexception-class-com-kuang-servlet-helloservlet-is-not-a-servlet-22749/
https://howtodoinjava.com/java/exception-handling/solved-the-superclass-javax-servlet-http-httpservlet-was-not-found-on-the-java-build-path-in-eclipse/
1条答案
按热度按时间8i9zcol21#
解决了!
我所要做的就是进入项目属性并在Project Faces下,将我的动态Web模块从2.5更改为5.0
JSTL警告可以在属性-〉Web-〉JSP文件-〉验证-〉自定义操作-〉TagExtraInfo类的其他问题下取消(只需将"警告"更改为"忽略")