JSTL <c:out value="${EL}">不能正确输出的问题
由于Jsp2.0向后兼容的特性, 当遇到使用Jsp 1.2(Servlet v2.3)的网站时会默认的禁用JSP2.0 EL,所以导致c:out不能正确输出。
(这里注意Jsp 1.2禁用JSP2.0的EL,而是去使用JSTL 1.0 taglib去解析EL。所以使用JSP 1.2+JSTL 1.0不会出问题,而使用了JSP 1.2+JSTL 1.1就会导致c:out不能正确输出)
启用EL或修改webv.xml为jsp2.0可以解决问题。
启用EL:在jsp页面中加入
<%@ page isELIgnored="false"%>
page指令的isELIgnored屬性是控制EL的使用權的,它的兩個值,true和false
如果 isELIgnored='true'表示禁用EL,isELIgnored='false' 表示可以使用EL, 默認是false
修改webv.xml为jsp2.0
为了用EL改为
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">
<display-name>WebModule1 </display-name>
</web-app>
参考:
JSTL 1.0 requires JSP 1.2 (J2EE 1.3 platform). The key difference between JSTL 1.0 and JSTL 1.1 is that the expression language (EL) has moved from the JSTL specification to the JSP specification. The EL is therefore now part of the JSP 2.0 specification, and JSTL 1.1 requires JSP 2.0 (J2EE 1.4 platform).
A web application developed for JSP 1.2 has a servlet 2.3 deployment descriptor (web.xml). JSP 2.0 provides backwards compatibility for JSP 1.2 web applications by disabling by default the EL machinery (i.e. evaluation of EL expressions) when a web application has a servlet 2.3 deployment descriptor. A web application that uses JSTL 1.0 and which is deployed with a servlet 2.3 deployment descriptor therefore runs without any modification in a J2EE 1.4 environment because EL expressions are ignored by JSP 2.0, and JSTL 1.0 keeps evaluating them as was the case with JSP 1.2.
To support backwards compatibility, JSTL 1.1 introduces new URIs that must be specified to use the new capabilities offered in JSTL 1.1. Among these new capabilities is the evaluation of EL expressions being performed by the JSP 2.0 container rather than JSTL itself. The new URIs for JSTL 1.1 are as follows:
- http://java.sun.com/jsp/jstl/core
- http://java.sun.com/jsp/jstl/xml
- http://java.sun.com/jsp/jstl/fmt
- http://java.sun.com/jsp/jstl/sql
The new URIs are similar to the old JSTL 1.0 EL URIs, except that jsp/ has been added in front of jstl, stressing JSTL's dependency on the JSP specification (which now "owns" the EL). It would have been desirable to move forward with the same EL URIs in JSTL 1.1, however this would have only been possible at the cost of losing full backwards compatibility. The JSTL Expert Group felt that maintaining backwards compatibility was more important than preserving the old URIs.
The JSTL 1.0 URIs are deprecated as of JSTL 1.1. If used, they should normally appear in a web application that has a servlet 2.3 deployment descriptor to disable the JSP 2.0 EL machinery. If used with a servlet 2.4 deployment descriptor, the JSP 2.0 EL machinery must be explicitely disabled for the pages where the JSTL 1.0 tag libraries are used. Consult the JSP specification for details.
http://jcp.org/aboutJava/communityprocess/final/jsr052/JSR52-ChangeLog_1.1_Final.html
JSP EL表达式
JSP EL表达式是包含在符号“${"与"}”之间。例如,${4*8}是一个EL表达式。在Java服务器技术中,不再保留“${"和"}”符号作为EL表达式的专用符号。执行表达式时,JSP容器可能将大括号视为循环的起始括号而显示错误,或得出错误的输出结果。因此,有时需要使用isElgnored属性禁用EL表达式是。
Servlet2.3规范未定义EL表达式,因此在JSP1.2中默认是禁用EL表达式,如果在JSP页面中出现Servlet2.3EL表达式,将被忽略。Servlet2.4定义了EL表达式的模式,而JSP2.0中默认启用JSP EL表达式。
<% @page isELIgnored = "true|false"%>
其中,page表示页面指令,isELIgnored确定是否应忽略对EL表达式进行计算。
如果isELIgnored设置为true,当EL表达式在静态文本或标签属性中出现时将被忽略;如果isELIgonred设置为false,EL表达式则由JSP容器进行计算。
本文来源于:尼克技术博客 http://www.ineeke.cn/ , 原文地址:http://www.ineeke.cn/archives/233/