java 将 JSTL 添加到 jsp (Tomcat 8)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28026991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:52:41  来源:igfitidea点击:

Adding JSTL to jsp (Tomcat 8)

javajsptomcatjstl

提问by user1007522

I want to use the JSTL library in my jsp's. Now I followed a tutorial and it told me to add this line to the jsp page:

我想在我的 jsp 中使用 JSTL 库。现在我遵循了一个教程,它告诉我将此行添加到 jsp 页面:

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

It gives me the error cannot resolve taglib with uri and then the URL.

它给了我错误无法用 uri 和 URL 解析 taglib。

I'm running tomcat 8. My web.xml is like this:

我正在运行 tomcat 8。我的 web.xml 是这样的:

<web-app version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

Does someone know how to fix this?

有人知道如何解决这个问题吗?

采纳答案by z21

You need to add jar for the jstllibrary in your classpath. If you are using maven, then add this dependency.

您需要jstl在类路径中为库添加 jar 。如果您使用的是 maven,则添加此依赖项。

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

Add this to your pom.xml.

将此添加到您的 pom.xml。

回答by SMA

To resolve this issue, you would need to do the following:

要解决此问题,您需要执行以下操作:

  • The jstl.jarshould be in your classpath. (Download jar/ pom)
  • Make sure you have the following taglib directive at the top of your jsp:

    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    
  • 的jstl.jar应该在你的classpath中。(下载jar/ pom
  • 确保您的 jsp 顶部有以下 taglib 指令:

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