`
demitong
  • 浏览: 7012 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

EL表达式无效问题《ZT》

阅读更多
今天遇到个小问题,EL表达式在JSP页面无效,仍然原样显示,网上查找解决办法,已解决。下面是这类问题的原因和几种解决办法:

原因:问题在web.xml配置文件上,web.xml声明部分一般分为如下版本的xsd,
         web-app_2_2.xsd
         web-app_2_3.xsd
         web-app_2_4.xsd
         web-app_2_5.xsd
         具体声明代码就不列出,网上可以找到,查找以前项目的web.xml文件也可以。 在jsp页面的<%@ page isELIgnored="false" %>声明中,将isELIgnored属性设为false,EL表达 式才可以正常显示,在2.4版本之前的版本,isELIgnored默认为true,所以只能在JSP页面设置这个属性为false才可以。2.4版本中isELIgnored属性默认为false,因此EL表达式可以直接使用。

方法:1.JSP页面中<%@ page isELIgnored="false" %>,每个页面都如此,就会很麻烦。
         2.将web.xml中的声明改为2.4版本,如下:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">

下面是官方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

PS: 我本来的版本是2.5,以前也没出过此类问题,感觉可能是Tomcat的版本不一样造成的问题,在Tomcat中的web.xml中貌似也有可以配置EL可用的定义。这种小问题虽然不起眼,但写程序时感觉还是很容易遇到的,而且只有在亲自写代码时才会碰到,书上是找不到的,所以积少成多,也许这就是经验积累的过程吧!

PS: 2.5版本的也是默认true,要在每个使用EL表达式的JSP设定isELIgnored为false,
另,引入JSTL可以在本地放置uri="/WEB-INF/c.tld"文件,也可以引入网上的解析文件uri="http://java.sun.com/jsp/jstl/core",同时别忘了需要2个jar包(jstl.jar和standard.jar)
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics