在 JSP 页面中使用 JSTL 标签库,访问 JSP 页面时抛出了如下异常信息:
org.apache.jasper.JasperException: /index.jsp (line: 261, column: 54) According to TLD or attribute directive in tag file, attribute value does not accept any expressions org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148) org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1234) org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:870) org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376) org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428) org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:889) org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376) org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428) org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434) org.apache.jasper.compiler.Node$Root.accept(Node.java:475) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376) org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1789) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:216) org.apache.jasper.compiler.Compiler.compile(Compiler.java:372) org.apache.jasper.compiler.Compiler.compile(Compiler.java:352) org.apache.jasper.compiler.Compiler.compile(Compiler.java:339) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) …… ……
因为使用了 JSP 2.0, 但又没有使用 JSTL 标签库的备用版本(RT库)
将 web.xml 中的 声明由 2.4 或 2.5 版本的修改为 2.3 版本,如:
<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">
修改为:
<!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>
JSTL 标签库的有两种 taglib 伪指令, 其中 RT 库即是依赖于 JSP 传统的请求时属性值, 而不是依赖于 EL 来实现:
只要将
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
改为
<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>