jsp页面中的EL表达式不被解析的问题

原因:问题在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)

posted on 2017-07-26 16:17  babyblue  阅读(2795)  评论(0编辑  收藏  举报