taglib指令使用JSTL类库发生的错误解决

问题描述:

在一个jsp页面里面调用 el 时出现的这个错误

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

异常信息:
Exception:According to TLD or attribute directive in tag file, attribute value does not accept any expression

但是:如<c:out value="haha"/>这样的表达式,不会有问题。
但如果用<c:out value="${sessionScope.username}"/>这样的el就报:
According to TLD or attribute directive in tag file, attribute value does not accept any expressions

所以我试着把标签库
换成了

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

之后,错误消失。

原因:

1. 可能是因为使用了JSP2.0版本, 同时又没有使用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就不行了, 这是版本不兼容引起的。 

2. jstl存在1.0和1.1的差异问题,用EL建议需要在1.1或1.2的版本下:

使用jstl1.1 只需要将1.0的为<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

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

猜你喜欢

转载自www.cnblogs.com/chenloveslife/p/8974038.html