---
title: "struts2 ognl 与 jsp2.1 el 的冲突问题"
author: "zero_dian"
date: "2008-01-23T17:18:00Z"
tags: []
slug: "struts2-ognl-jsp2-1-el"
draft: false
lastmod: "2008-01-23T17:18:00Z"
id: 442635
url: "https://zero-dian.iteye.com/blog/442635"
---

tomcat6 , jetty6 采用 jsp2.1。  
由于 nio 带来的性能提升，tomcat6 不能被忽略。

办法1：

[http://www.devzuz.org/blogs/bporter/2006/08/05/1154706744655.html](http://www.devzuz.org/blogs/bporter/2006/08/05/1154706744655.html "http://www.devzuz.org/blogs/bporter/2006/08/05/1154706744655.html")

&lt;ww:select list="#{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}" /&gt;

改用-------------------------------------------------------------  
&lt;ww:select list="#@java.util.HashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}" /&gt;

这样 jsp2.1 el 就不会有问题了。

办法2： 对于旧的程序，不愿意改了，可以向后兼容  
[http://today.java.net/lpt/a/272#backwards-compatibility](http://today.java.net/lpt/a/272#backwards-compatibility "http://today.java.net/lpt/a/272#backwards-compatibility")

必须用 Servlet **2**.**5** XSD.  
&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5" xmlns:xsi="http://www.&lt;wbr&gt;&lt;/wbr&gt;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;

```
<jsp-property-group>
  <deferred-syntax-allowed-as-literal>
    true
  </deferred-syntax-allowed-as-literal>


</jsp-property-group>
```

或者在页面中

```
<%@page  language="java" deferredSyntaxAllowedAsLiteral="true" %>

办法3 ：不用 jsp2.1 el

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


http://www.mail-archive.com/dev@struts.apache.org/msg28920.html

我现在的疑问
在一个页面中采用两个 el 引擎，是否会对性能造成一定影响？
较小。
```

```
tomcat6,jetty6采用jsp2.1。
由于nio带来的性能提升，tomcat6不能被忽略。

办法1：(全英文方法)
Jetty6(whichIusefordaytodaydevelopment)automaticallyusesJSP2.1ifyouareonJDK5.0orabove,regardlessofwhatyouhavespecifiedinweb.xml.

ThishadbeenbitingmeonWebWork,becauseoftheintroductionofunifiedEL.Thefollowingisnolongervalid:

<ww:selectlist="#{'default':'Maven2.xRepository','legacy':'Maven1.xRepository'}"/>

But,toescapeitwith\#{doesn'tworkonTomcat5andother2.0containers.

Thesolution?

<ww:selectlist="#@java.util.HashMap@{'default':'Maven2.xRepository','legacy':'Maven1.xRepository'}"/>

ThankgoodnessOGNLhadthisothersyntaxformapsthatdoesn'tlooklikeanexpression:)


<ww:selectlist="#{'default':'Maven2.xRepository','legacy':'Maven1.xRepository'}"/>

改用-------------------------------------------------------------
<ww:selectlist="#@java.util.HashMap@{'default':'Maven2.xRepository','legacy':'Maven1.xRepository'}"/>

这样jsp2.1el就不会有问题了。

办法2：对于旧的程序，不愿意改了，可以向后兼容
http://today.java.net/lpt/a/272#backwards-compatibility

必须用Servlet2.5XSD.
<web-appxmlns="http://java.sun.com/xml/ns/javaee"version="2.5"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<jsp-property-group>
<deferred-syntax-allowed-as-literal>
true
</deferred-syntax-allowed-as-literal>


</jsp-property-group>

或者在页面中

<%@pagelanguage="java"deferredSyntaxAllowedAsLiteral="true"%>

办法3：不用jsp2.1el

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