How to disable EL expression for multiple lines in JSP

On some JSP pages I want to show the page

<h4>${id}</h4> 

However, EL will try to evaluate the id variable and leave it empty (not find the variable) or the actual value.

  <h4>123</h4> 

I know that there is

 <%@ page isELIgnored="false" %> 

but this will disable EL for the entire JSP page.

Is there a way to disable EL for only a few lines?

Thanks guys, I am also writing a post about this. http://www.ke-cai.net/2010/12/jquery-template-markup-and-jsp.html

+4
source share
3 answers

From the JSP 2.0 spec :

Citation in EL Expressions

  • There is no special citation mechanism in EL expressions; use the literal '${' if literal ${ is required, and expressions are allowed for the page. For example, the estimate of ${'${'} is '${' . Please note that ${'}'} is legal and is simply evaluated before '}' .

So, in your case, instead of:

 <h4>${id}</h4> 

do the following:

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

This, of course, does not look beautiful, but this is what the Community Community process was decided on.

+4
source

The backslash is the easiest.

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

Edit: I used this method in combination with the official jQuery Template plugin with variables of the same syntax.

+5
source

Think of $ as an HTML / XML object.

 <h1>&#36;{id}</h1> 
+1
source

All Articles