关于jsp中使用jstl的问题

一般稍不小心就会出现下面的错误:

  the absolute uri:http://java.sun.com/jstl/core cannot be resolved.一个例子如:http://stackoverflow.com/questions/4928271/jstl-1-2-the-absolute-uri-http-java-sun-com-jstl-core-cannot-be-resolved

解决办法:

  如果你的项目是使用Maven进行管理的话,那么很好办,只需要在pom.xml文件中添加:

1
2
3
4
5
6
7
8
9
10
11
<dependency>
         <groupId>jstl</groupId>
         <artifactId>jstl</artifactId>
         <version>1.1.2</version>
     </dependency>
 
     <dependency>
         <groupId>taglibs</groupId>
         <artifactId>standard</artifactId>
         <version>1.1.2</version>
     </dependency>

  然后在你相应的jsp文件中添加:

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

  就ok了。

当然如果你的项目没有使用maven进行管理的话,可以手动添加支持。具体的做法是:

首先去http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/ 下载标准标签库的发行文件。

为了在 JSP 中使用 Java 标准标签库,需要: 

1. 将 TLD 文件拷贝到 WEB-INF/tld 
2. 将 JAR 文件拷贝到 WEB-INF/lib

一个简单的实例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c-rt.tld" prefix="c-rt" %>
 
<html>
 
<head>
    <title>Java Code Geeks Snippets - Simple JSTL in JSP Page</title>
</head>
 
<body>
 
    <c-rt:if test='<%= request.getParameter("myparam") != null %>'>
        <%= request.getParameter("myparam") %>
    </c-rt:if>
 
</body>
</html>

  大家要注意的是上面示例代码的这一行:

1
<%@ taglib uri="/WEB-INF/tld/c-rt.tld" prefix="c-rt" %>
原文地址:https://www.cnblogs.com/lyzblog/p/4272731.html