我已经阅读了关于 SO 上这个问题的几乎所有答案,并尝试了十几种不同的“解决方案”,但我无法让 JSTL 在使用 Tomcat 8.0 中的 servlet 3.1 的 Spring Boot Web 应用程序中工作。我继续收到此错误:
The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application.
我使用 Maven 来构建项目,但也手动复制了 JAR,希望能有所帮助,但可惜没有!我希望我只是忽略了一些愚蠢的事情。有人可以告诉我我做错了什么吗?
我尝试过的事情(对于所有这些,这是一个简单的 index.jsp 文件中包含的行 -
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
在我的 pom.xml 中添加了以下依赖项(删除 XML 字符以更好地格式化)
<dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
这会将 jstl-1.2.jar 放在我的 WEB-INF/lib 目录中,并且当我部署到 Tomcat 时我已经确认它在那里 - 这不起作用
根据此处的建议删除了上述依赖项并添加了这些依赖项(http://www.murraywilliams.com/2011/11/running-jstl-1-2-on-tomcat-7-using-maven/)
<dependency> <groupId>org.glassfish.web</groupId> <artifactId>jstl-impl</artifactId> <version>1.2</version> <exclusions> <exclusion> <artifactId>servlet-api</artifactId> <groupId>javax.servlet</groupId> </exclusion> <exclusion> <artifactId>jsp-api</artifactId> <groupId>javax.servlet.jsp</groupId> </exclusion> </exclusions> </dependency>
这会在我的 WEB-INF/lib 目录中添加两个额外的 JAR 文件,一个 jstl-api-1.2.jar 和 jstl-impl-1.2.jar,当我部署到 Tomcat 时我已经确认它们在那里 - 这不起作用
我还尝试将每个依赖项的范围更改为“提供”,同时将相应的 JAR 放在 Tomcat 的 lib 目录中并重新启动 Tomcat,但仍然无法正常工作。
这是我的 web.xml 标头
<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_3_1.xsd"
version="3.1">
无论如何,非常感谢任何帮助!