---
title: "问题解决方案-解决JSP页面中的EL表达式不被解析的问题"
author: "stef831018"
date: "2012-12-21T11:12:05Z"
tags: []
categories: ["编程语言"]
slug: "jsp-el"
draft: false
lastmod: "2012-12-22T11:11:51Z"
id: 1751589
url: "https://stefyn.iteye.com/blog/1751589"
---

**解决JSP页面中的EL表达式不被解析的问题**

今天遇到EL表达式不被解析的问题，现象如下：

在\*\*.jsp中设定了&lt;c:set scope="request" var="sysCtxp" value="${pageContext.request.contextPath}" /&gt;，但是使用${sysCtxp}却无法取得值，输出后是"${sysCtxp}"字符串，EL表达式没有被解析。

反复尝试过一些方案后，将此类问题的解决方案归纳如下：

1、升级Tomcat容器至Tomcat6或以上；但请注意，该方法不能保证一定可以解决该问题，尝试过发现，即使6.x的不同版本也存在同样的问题，似乎与Tomcat6下lib目录中的jsp-api.jar/servlet-api.jar有关系，但是使用7.x版本，目前还没有出现该问题。

2、修改web.xml中&lt;web-app&gt;的属性。

一般修改该属性时，可以使用eclipse创建动态web工程方式，在创建时选定servlet2.4以上的版本，创建后会自动生成web.xml文件，然后从中摘出即可，最好不手写，以免出错。

 

以下是把web.xml中&lt;web-app&gt;版本修改到2.4或以上的样例代码：

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

&lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 

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

 

注意：如果web.xml中声明部分的schema版本为2.4或者以上，而tomcat使用的是5.5.x以下的版本的时候就会出现在页面直接显示而不解析jstl/el表达式。如果web.xml中声明部分的schema版本为2.5或者以上，tomcat使用使用的是6.0以上则不出现这种问题。

3、在使用了EL表达式的所有JSP页面中，加入&lt;%@ page isELIgnored="false" %&gt;，可以把该语句放置到共通jsp页面上，然后在其他页面上include即可。

下面是官方Documention中isELIgnored Attribute的解释： 

The isELIgnored Attribute 

• Format 

– &lt;%@ page isELIgnored="false" %&gt; 

– &lt;%@ page isELIgnored="true" %&gt; 

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