日期:2014-05-16  浏览次数:20379 次

使用jstl标签报错问题

JSP中出现According to TLD or attribute directive in tag file, attribute value does not accept any expressions 收藏
应用部署运行的时候出现JSP异常, 发生在使用JSTL库的时候: According to TLD or attribute directive in tag file, attribute value does not accept any expressions, 可能是因为使用了JSP2.0版本, 同时又没有使用JSTL core库的备用版本(RT库), 以下有两种处理方法:

1. 修改web.xml.

<web-app 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" version="2.4">
改为2.3版本的

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
2. 使用JSTL core RT库

JSTL core库的有两种taglib伪指令, 其中RT库即是依赖于JSP传统的请求时属性值, 而不是依赖于EL来实现(称为EL库.JSP2.0将支持EL)

JSP中使用<%@ taglib uri=http://java.sun.com/jstl/core prefix="c"%>在2.3版本都可以,在2.4就不行了, 难道是版本不兼容吗?

只要将

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

<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>
就没有问题了

?

由于现行的JSTL有两种版本,因此使用起来还是有一些区别需要注意的。
????????1.JSTL1.0是支持Servlet2.3和JSP1.2规范的。http://java.sun.com/jstl/core
????????2.JSTL1.1是支持Servlet2.4和JSP2.0规范的。http://java.sun.com/jsp/jstl/core

????????这两种JSTL1.1的增强特性有以下几点:
????????1.JSTL1.1可以使用函数标签库
????????2.JSTL1.1规范中,JSP2.0容器已经能够独立的理解任何EL表达式。EL可以独立出现在JSP页面的任何角落。
????????3.JSTL1.1中的EL表达式不支持(X>Y ? X=1 : Y=2)的表达式

????????以下是一些容器支持的JSTL版本说明:
????????

?容器 Servlet JSP Specification
?Weblogic 8.1 2.3???? 1.2
Tomcat 3.3.1a 2.2 1.1
Tomcat 4.1.27 2.3 1.2
Tomcat 5.0.12Beta 2.4 2.0

?

?

?

?

近日做一个小系统,使用了Struts,还用到了JSTL。这套配置在以前开发项目的时候就用过的,不过当时没有深入了解。所以,导致本次使用时,遇到了一个小问题,浪费了一点时间。

所以,做了一个小小的调查,搞清楚了JSTL1.0和JSTL1.1的区别及使用方法。

现象

在<c:out>标签中使用了EL,结果运行时报错。说根据tld文件的说明,该标签不支持表达式(EL)。

原文为:

According to TLD or attribute directive in tag file, attribute value does not accept any expressions

依赖的环境及jar

1. 使用的标签库是从apache上down下来的。

??? http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html

??? 一共两个文件,一个jstl.jar,一个standard.jar。

2. tomcat是5.0系列的。

原因

在JSP中声明uri的时候,写成了jstl 1.0的uri。

而1.0确实是不支持EL的,但是它的tld文件又存在于1.1的jar包中。

经过调查确认,总结如下三点:

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