找不到“http://java.sun.com/jsp/jstl/core"的标签库描述符 [英] Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

查看:47
本文介绍了找不到“http://java.sun.com/jsp/jstl/core"的标签库描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将其包含在我的 JSP 页面的最顶部:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

我已经将 JSTL JAR 文件放在 WEB-INF/lib 目录中.但是,JSP 仍然无法解析 taglib.我收到以下错误:

<块引用>

找不到您正在使用Tomcat 7. 在这种情况下,您需要 JSTL 1.2.但是,您有一个 jstl.jar 文件,而 JSTL 1.2 清楚地包含了版本号,就像 jstl-1.2.jar 一样.唯一的文件名 jstl.jar 是 JSTL 1.0 和 1.1 的典型名称.此版本需要 /WEB-INF/lib 中的 standard.jar,其中包含必要的 TLD 文件.但是,在您的特定情况下,/WEB-INF/lib 中显然缺少 standard.jar,这正是无法解析 taglib URI 的原因.

要解决这个问题,您必须删除错误的 JAR 文件,请下载 jstl-1.2.jar 并将其全部放在 /WEB-INF/lib 中.就这样.您不需要提取它,也不需要在项目的构建路径中摆弄.

不要忘记删除那个松散的 c.tld 文件.它绝对不属于那里.这确实在互联网其他地方的一些糟糕的教程或答案中有所说明.这是一个由重大误解和错误配置引起的神话.永远不需要在类路径中有一个松散的 JSTL TLD 文件,在以前的 JSTL 版本中也不需要.

如果您使用的是 Maven,请使用以下坐标:

<groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></依赖>

您还应该确保您的 web.xml 声明为至少 Servlet 2.4,因此不是 Servlet 2.3 或更早版本.否则 JSTL 标签内的 EL 表达式将无法工作.选择与目标容器匹配的最高版本,并确保 web.xml 中的任何位置都没有.这是一个与 Servlet 3.0 (Tomcat 7) 兼容的示例:

<网络应用程序xmlns="http://java.sun.com/xml/ns/javaee";xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"版本=3.0"><!-- 在这里配置.--></web-app>

###另见:

I have included this at the very top of my JSP page:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

I already placed the JSTL JAR file in the WEB-INF/lib directory. But still, the JSP can't resolve the taglib. I get the below error:

Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"

I am using Eclipse Juno and the project structure is shown below:

解决方案

Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"

Based on one of your previous questions you're using Tomcat 7. In that case you need JSTL 1.2. However, you've there a jstl.jar file while JSTL 1.2 has clearly the version number included like so jstl-1.2.jar. The sole filename jstl.jar is typical for JSTL 1.0 and 1.1. This version requires a standard.jar along in /WEB-INF/lib which contains the necessary TLD files. However, in your particular case the standard.jar is clearly missing in /WEB-INF/lib and that's exactly the reason why the taglib URI couldn't be resolved.

To solve this you must remove the wrong JAR file, download jstl-1.2.jar and drop it in its entirety in /WEB-INF/lib. That's all. You do not need to extract it nor to fiddle in project's Build Path.

Don't forget to remove that loose c.tld file too. It absolutely doesn't belong there. This is indeed instructed in some poor tutorials or answers elsewhere in the Internet. This is a myth caused by a major misunderstanding and misconfiguration. There is never a need to have a loose JSTL TLD file in the classpath, also not in previous JSTL versions.

In case you're using Maven, use the below coordinate:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

You should also make sure that your web.xml is declared conform at least Servlet 2.4 and thus not as Servlet 2.3 or older. Otherwise EL expressions inside JSTL tags would in turn fail to work. Pick the highest version matching your target container and make sure that you don't have a <!DOCTYPE> anywhere in your web.xml. Here's a Servlet 3.0 (Tomcat 7) compatible example:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <!-- Config here. -->

</web-app>

###See also:

这篇关于找不到“http://java.sun.com/jsp/jstl/core"的标签库描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆