在jsp页面中使用JSTL标签前,需要先导入依赖的jar包,并使用taglib指令将标签库描述符文件导入到jsp页面中。
JSTL1.1及之前的版本导入的jar包有两个:jstl.jar和standard.jar。到了1.2的版本,只需要jstl.jar一个jar包。
JSTL1.1及之前的taglib指令写法:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
JSTL1.2 taglib指令写法
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
另外,JSTL1.2版本需要servlet 2.5及以上版本 。
servlet、tomcat、jdk版本对应关系,参考地址:http://tomcat.apache.org/whichversion.html
Servlet Spec | JSP Spec | EL Spec | WebSocket Spec | Authentication (JASIC) Spec | Apache Tomcat Version | Latest Released Version | Supported Java Versions |
---|---|---|---|---|---|---|---|
6.0 | TBD | TBD | TBD | TBD | 10.1.x | 10.1.0-M4 (alpha) | 11 and later |
5.0 | 3.0 | 4.0 | 2.0 | 2.0 | 10.0.x | 10.0.10 | 8 and later |
4.0 | 2.3 | 3.0 | 1.1 | 1.1 | 9.0.x | 9.0.52 | 8 and later |
3.1 | 2.3 | 3.0 | 1.1 | 1.1 | 8.5.x | 8.5.68 | 7 and later |
3.1 | 2.3 | 3.0 | 1.1 | N/A | 8.0.x (superseded) | 8.0.53 (superseded) | 7 and later |
3.0 | 2.2 | 2.2 | 1.1 | N/A | 7.0.x (archived) | 7.0.109 (archived) | 6 and later (7 and later for WebSocket) |
2.5 | 2.1 | 2.1 | N/A | N/A | 6.0.x (archived) | 6.0.53 (archived) | 5 and later |
2.4 | 2.0 | N/A | N/A | N/A | 5.5.x (archived) | 5.5.36 (archived) | 1.4 and later |
2.3 | 1.2 | N/A | N/A | N/A | 4.1.x (archived) | 4.1.40 (archived) | 1.3 and later |
2.2 | 1.1 | N/A | N/A | N/A | 3.3.x (archived) | 3.3.2 (archived) | 1.1 and later |