el表达式不起作用

 

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

tomcat5.5的版本。

web.xml

<?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">

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

<?xml version="1.0" encoding="UTF-8"?>

<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">

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

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

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

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

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

后记:实际上对于jboss4(tomcat5),即使在web.xml中配置了以上信息也是不管用的,不知道什么原因,可能是因为tomcat5只支持servlet2.4,不支持2.5以上,没有仔细追踪下去,所以只能修改WEB.XML至2.4或者每个jsp页面都添加<%@ page isELIgnored="false"%>,再或者就是升级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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值