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

JSP页面EL表达式无效的问题

    博客分类:
  • Java
阅读更多
以前用WSAD wizard做的,都可以在JSP页面中解析到EL表达式,当然前提是JSP2.0的情况下。
今天遇到了一个莫名其妙的问题。刚下载Eclipse3.3+MyEclipse6.0体验的过程中,遇上了解析不到EL表达式的问题。经过好几个小时的琢磨终于发现了,给大家share一下:
问题就出在建Web Project的时候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声明部分吧,如下:
web-app_2_2.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!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
<?xml version="1.0" encoding="UTF-8"?>
<!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
<?xml version="1.0" encoding="UTF-8"?>
<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
<?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">


确定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
分享到:
评论
15 楼 dwangel 2013-05-08  
shaka 写道
我的问题一样,可是我在jsp设置了isELIgnored,还是没起作用,真是搞不定了. 不知道是哪儿的问题,这个和引用的jar包有没有关系

对,是有依赖包

我一般用maven的,dependency里加(具体哪个我忘了,都加就是了,好像是jstl那个)

<!-- JSTL & Servlet -->
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- end of JSTL & Servlet -->
14 楼 shaka 2013-05-08  
我的问题一样,可是我在jsp设置了isELIgnored,还是没起作用,真是搞不定了. 不知道是哪儿的问题,这个和引用的jar包有没有关系
13 楼 guokecheng 2008-09-24  
只有Servlet2.4版本默认支持EL,如果在MyEclipse新建web项目时,选择Java EE5.0的时候是用Servlet2.5的。它默认是不支持EL.要在页面声明<%@ page isELIgnored="false" %> 方有效,有谁知道在哪个配置文件中一次性声明,就不用每个页面都要声明的话,请告诉我啊,谢谢
12 楼 accphc 2008-09-24  
<jsp-config>难道只能在2.4下用???
11 楼 volking 2008-09-23  
zhende 写道

哥们s,应该写成忽略false啊,你们写个忽略为ture,那肯定不行了。&nbsp;
引用
&lt;jsp-config&gt;&nbsp; &nbsp;&nbsp;&nbsp; &lt;jsp-property-group&gt;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt;&nbsp; &nbsp;&nbsp;&nbsp; &lt;el-ignored&gt;false&lt;/el-ignored&gt;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/jsp-property-group&gt;&nbsp; &lt;/jsp-config&gt;


我试过,没用。只能在页面加入才行。
10 楼 zhende 2008-09-19  
哥们s,
应该写成忽略false啊,你们写个忽略为ture,那肯定不行了。
 
引用

<jsp-config> 
    <jsp-property-group> 
        <url-pattern>*.jsp</url-pattern> 
    <el-ignored>false</el-ignored> 
    </jsp-property-group> 
</jsp-config>


9 楼 srdrm 2008-08-28  
el需要 servlet 2.4 吧
8 楼 yangpeihai 2008-06-12  
EL要在jstl2.0以上才能支持
7 楼 dwangel 2008-01-21  
el只在2.4环境下支持吧,所以web.xml必须配为2.4以上的。
貌似是根据web.xml来判断版本的。
6 楼 jakoes 2008-01-20  
<jsp-config>   
    <jsp-property-group>   
        <url-pattern>*.jsp</url-pattern>   
    <el-ignored>true</el-ignored>   
    <!-- <el-ignored>false</el-ignored> -->   
    </jsp-property-group>   
</jsp-config> 
5 楼 gimgen1026 2008-01-15  
试了,还不行.. --;;;
4 楼 gimgen1026 2008-01-14  
没有jstl定义啊,跟这个还有关系吗?
我试试
3 楼 ztroma 2008-01-14  
web.xml里面有没有
<taglib><taglib-uri>/WEB-INF/jstl/c.tld</taglib-uri>   
<taglib-location>/WEB-INF/jstl/c.tld</taglib-location></taglib>

这样的定义?
2 楼 gimgen1026 2008-01-13  
你说的这个web.xml里确实有jsp-config的属性..见识,谢谢!
于是刚才自己试了一下,光web.xml里写
<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
    <el-ignored>true</el-ignored>
    <!-- <el-ignored>false</el-ignored> -->
    </jsp-property-group>
</jsp-config>

仍然没反应..
在网上也找了找,结果有些人说是Tomcat里web.xml和jsp页面上都得声明,大概是这意思。
skydream有更详细有效的配置方法吗?
1 楼 skydream 2008-01-13  
直接在web.xml里面设置ELIgnore不好吗?

我记得是有这个配制项的,这样就不必每个jsp页面都设置一次了。

相关推荐

Global site tag (gtag.js) - Google Analytics