---
title: "el表达式不起作用"
author: "tujunlan"
date: "2013-11-14T16:21:18Z"
tags: ["el表达式", "tomcat5"]
categories: ["编程语言"]
slug: "el"
draft: false
lastmod: "2013-11-21T15:59:24Z"
id: 1974783
url: "https://tujunlan.iteye.com/blog/1974783"
---

今天用el表达式，老是得不到后台传过来的值。该导入的jar包和标签库也都导入了。还是不起作用。后来在网上找到一篇文章。解决了。原来是版本的问题。现在贴一下。

tomcat5.5的版本。

web.xml

&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;

&lt;web-app xmlns="[http://java.sun.com/xml/ns/j2ee](http://java.sun.com/xml/ns/j2ee)"

    xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"

    xsi:schemaLocation="[http://java.sun.com/xml/ns/j2ee](http://java.sun.com/xml/ns/j2ee) [http://java.sun.com/xml/ns/j2ee/web-app\_2\_4.xsd](http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd)"

    version="2.4"&gt;

对于tomcat5，2.4版本默认启用el表达式，如果使用2.5版本及以上，默认el表达式是关闭的（注意，这里特地说明了是对于tomcat5，对于tomcat6及以上版本，web.xml只要是配置2.4及以上版本的的，默认都是启用el表达式的）

&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;web-app xmlns="[http://java.sun.com/xml/ns/javaee](http://java.sun.com/xml/ns/javaee)" 

    xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](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)   

   [http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd](http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd)"&gt;

那么对应2.5的web.xml --&gt;  jsp页面里应该增加&lt;%@ page isELIgnored="false"%&gt;

一句话，凡是部署描述文件遵循Servlet2.4规范的WEB应用，EL表达式的计算默认是启用的，而未遵循的，则EL表达式的计算默认是禁用的。

所以解决方案还可以是：将web.xml中的DTD(文档类型定义)改为2.4的版本

或者  
       对于一个单个JSP页面，你可以使用定义page指令来设置jsp页面是否支持EL。默认是支持EL(如果要页面不支持EL，请设置为isELIgnored=true;  
&lt;%@ page isELIgnored＝"true|false"%&gt;

       对于整个JSP应用程序，要修改WEB.XML配置(tomcat5.0.16默认是支持EL的);  
&lt;jsp-property-group&gt;  
&lt;description&gt; For config the ICW sample application &lt;/description&gt;  
&lt;display-name&gt;JSPConfiguration&lt;/display-name&gt;  
&lt;url-pattern&gt;/jsp/datareset.jsp&lt;/url-pattern&gt;  
&lt;el-ignored&gt;false&lt; / el-ignored&gt;  
&lt;page-encoding&gt;ISO-8859-1&lt;/page-encoding&gt;  
&lt;scripting-invalid&gt;true&lt;/scripting-invalid&gt;  
&lt;include-prelude&gt;/jsp/prelude.jspf&lt;/include-prelude&gt;  
&lt;include-coda&gt;/jsp/coda.jspf&lt;/include-coda&gt;  
&lt;/jsp-property-group&gt;

后记：实际上对于jboss4（tomcat5），即使在web.xml中配置了以上信息也是不管用的，不知道什么原因，可能是因为tomcat5只支持servlet2.4，不支持2.5以上，没有仔细追踪下去，所以只能修改WEB.XML至2.4或者每个jsp页面都添加&lt;%@ page isELIgnored＝"false"%&gt;，再或者就是升级tomcat至6及以上，以下记录别人总结的el表达式不管用的原因：

 

In other words, the EL expression doesn't get evaluated at all and is showing as plain text? That can have one or more of the following causes:

1. Application server in question doesn't support JSP 2.0.
2. The `web.xml` is not declared as Servlet 2.4 or higher.
3. The `<%@page %>` of JSP is configured with `isELIgnored=true`.
4. The `web.xml` is configured with `<el-ignored>true</el-ignored>` in `<jsp-config>`.

Tomcat 5.5 is Servlet 2.4/JSP 2.0, so #1 can be scratched. You didn't change anything in webapp before deploying I assume, so #3 and #4 can likely be scratched. Now left #2. Maybe you declared it as Servlet 2.5 for Tomcat 6.0 while the Tomcat 5.5 only understands up to with Servlet 2.4. This way everything will become a mess as Tomcat would then fallback to least compatibility modus. You need to redeclare `web.xml` as **Servlet 2.4** so that it will work in both Tomcat 5.5 and 6.0.