关于EL表达式在JSP页面中不能识别的问题

来源:互联网 发布:人工蜂群算法 无人机 编辑:程序博客网 时间:2024/05/29 03:38

EL的全称是Expression Language。

有三种解决方式:

(1)设置整个应用服务器下的所有项目是否解析el表达式(控制所有项目)

即在web.xml文件的版本支持问题,下面

(2)设置整个项目使用el表达式,需要在web.xml中加上 (控制一个项目) 

<jsp-config>  

<jsp-property-group> 

<el-ignored>false</el-ignored> 

</jsp-property-group>

</jsp-config>
(3)设置某个jsp页面使用el表达式,需要在jsp页面加上(控制单个页面)

<%@ page isELIgnored="false"%>

在默认情况下,Servlet 2.3 / JSP 1.2是不支持EL表达式的,而Servlet 2.4 / JSP 2.0支持。 servlets 2.4这个版本的isELIgnored默认设置为false。

所以使用web.xml里用web-app_2_4.xsd声明的时候在JSP页面不用特意声明。

更详细的列出各版本web.xml声明部分吧,如下: 

web-app_2_2.xsd 
Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/dtd/web-app_2_2.dtd">  

web-app_2_3.xsd 
Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!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_4.xsd 
Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <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">  

web-app_2_5.xsd 
Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  


确定web.xml里的xsd版本之后一定要在JSP的声明(<%@page %>)部分加一行,如下: 
<%@ page isELIgnored="false" %> 
这样设为false才能解析EL表达式。 
经过各版本的test之后.... 
注意!! 其中servlets 2.4(我没记错的话JSP 2.0出来之后的第一个版本),这个版本的isELIgnored默认设置为false。所以使用web.xml里用web-app_2_4.xsd声明的时候在JSP页面不用特意声明。 

下面是官方Documention中isELIgnored Attribute的详解: 
The isELIgnored Attribute 
• Format 
– <%@ page isELIgnored="false" %> 
– <%@ page isELIgnored="true" %> 
Purpose 
– To control whether the JSP 2.0 Expression Language 
(EL) is ignored (true) or evaluated normally (false). 
• Notes 
– If your web.xml specifies servlets 2.3 (corresponding to 
JSP 1.2) or earlier, the default is true 
• But it is still legal to change the default—you are permitted 
to use this attribute in a JSP-2.0-compliant server 
regardless of the web.xml version. 
– If your web.xml specifies servlets 2.4 (corresponding to 
JSP 2.0) or earlier, the default is false