jstl1.0不支持el表达式,假如使用的版本为jstl1.0,则在使用在<c:out>标签中使用了EL表达式的时候会报错:
原文为:
According to TLD or attribute directive in tag file, attribute value does not accept any expressions
jstl1.0确实是不支持EL的,但是它的tld文件又存在于1.1的jar包中。
解压standard-1.1.2.jar中在META-INF文件夹中会看到:c.tld、c-1_0.tld
c.tld:代表jstl版本为1.1
c-1_0.tld:代表jstl版本为1.0
1. jstl 1.0和1.1支持的servlet,jsp规范都不相同,支持相应规范的tomcat的版本也有要求的。具体如下。
NOTE: Standard-1.1 (JSTL 1.1) requires a JSP container that supports the Java Servlet 2.4 and JavaServer Pages 2.0 specifications. Jakarta Tomcat 5 supports the new specifications. The Standard-1.1 taglib has been tested with Tomcat 5.0.3. Standard-1.0 (implementation of the JSTL 1.0 specification) requires a JSP container that supports the Java Servlet 2.3 and JavaServer Pages 1.2 specifications. Jakarta Tomcat 4 supports these specifications. The Standard 1.0 taglib has been tested with Tomcat 4.1.24.
2. web.xml中要申明相应的servlet版本。
JSTL1.1和JSP2.0需要servlet2.4
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4 " xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4 .xsd">
JSTL1.0和JSP1.2需要servlet2.3
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.3 " xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_3 .xsd">
3. JSTL1.0和JSTL1.1的uri是不一样的,但是他们的tld文件同时存在于同一个standard.jar中。
解压缩下载的standard.jar,你会在/META-INF/下发现有一个c-1_0.tld,还有一个c.tld。
其中c-1_0.tld是JSTL1.0的core标签库的tld文件,c.tld是JSTL1.1的core标签库的tld文件。
用文本软件打开两个文件就会找到具体的uri。
JSTL1.0的使用方法为:
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
JSTL1.1的使用方法为:
<%@ taglib uri="http://java.sun.com/jsp /jstl/core" prefix="c" %>
也可以把c-1_0.tld或者c.tld 复制到WEB-INF下面,在jsp中引用即可:例如<%@ taglib uri="/WEB-INF/tag/c.tld" prefix="c" %>
servlet和tomcat版本对应关系:
Servlet Spec | JSP Spec | EL Spec | WebSocket Spec | JASPIC Spec | Apache Tomcat version | Actual release revision | Supported Java Versions |
---|---|---|---|---|---|---|---|
4.0 | TBD (2.4?) | TBD (3.1?) | TBD (1.2?) | 1.1 | 9.0.x | 9.0.0.M9 (alpha) | 8 and later |
3.1 | 2.3 | 3.0 | 1.1 | 1.1 | 8.5.x | 8.5.4 | 7 and later |
3.1 | 2.3 | 3.0 | 1.1 | N/A | 8.0.x (superseded) | 8.0.35 (superseded) | 7 and later |
3.0 | 2.2 | 2.2 | 1.1 | N/A | 7.0.x | 7.0.70 | 6 and later (7 and later for WebSocket) |
2.5 | 2.1 | 2.1 | N/A | N/A | 6.0.x | 6.0.45 | 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 |