简体   繁体   English

如何在JSP中禁用几行的EL表达式

[英]how to disable EL expression for a few lines in JSP

In some JSP pages, I want to the page display 在一些JSP页面中,我想要页面显示

<h4>${id}</h4>

However, EL will try to evaluate "id" variable and leave it to blank(not find the variable) or the actual value. 但是,EL将尝试评估“id”变量并将其留空(找不到变量)或实际值。

 <h4>123</h4>

I know there is a 我知道有一个

<%@ page isELIgnored="false" %>

but this will disable EL for the whole JSP page. 但这将禁用整个JSP页面的EL。

Is there any way to disable EL just for a few lines? 有没有办法只为少数几行禁用EL?

Thanks guys, I also write a post about this. 谢谢大家,我也写了一篇关于此的帖子。 http://www.ke-cai.net/2010/12/jquery-template-markup-and-jsp.html http://www.ke-cai.net/2010/12/jquery-template-markup-and-jsp.html

Backslash is the easiest. 反斜杠是最简单的。

<h4>\${id}</h4>

Edit: I have used this method in conjunction with the offical jQuery Template plugin which has variables of the same syntax. 编辑:我已经将此方法与官方jQuery模板插件结合使用,该插件具有相同语法的变量。

From the JSP 2.0 spec : JSP 2.0规范

Quoting in EL Expressions 引用EL表达式

  • There is no special quoting mechanism within EL expressions; EL表达式中没有特殊的引用机制; use a literal '${' if the literal ${ is desired and expressions are enabled for the page. 如果需要文字${并且为页面启用了表达式,则使用文字'${' For example, the evaluation of ${'${'} is '${' . 例如, ${'${'}的评估是'${' Note that ${'}'} is legal, and simply evaluates to '}' . 请注意, ${'}'}是合法的,只需评估为'}'

So in your case, instead of: 所以在你的情况下,而不是:

<h4>${id}</h4>

do this: 做这个:

<h4>${'${'}id}</h4>

It certainly doesn't look pretty but it's what the Java Community Process settled on. 它当然看起来并不漂亮,但它是Java Community Process的基础。

$表示为HTML / XML实体。

<h1>&#36;{id}</h1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM