Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable EL expression for a few lines in JSP

Tags:

java

jsp

jstl

el

In some JSP pages, I want to the page display

<h4>${id}</h4>

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

 <h4>123</h4>

I know there is a

<%@ page isELIgnored="false" %>

but this will disable EL for the whole JSP page.

Is there any way to disable EL just for a few lines?

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

like image 743
Ke CAI Avatar asked Dec 22 '22 20:12

Ke CAI


2 Answers

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.

like image 106
gbakernet Avatar answered Dec 24 '22 11:12

gbakernet


From the JSP 2.0 spec:

Quoting in EL Expressions

  • There is no special quoting mechanism within EL expressions; 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.

like image 39
Asaph Avatar answered Dec 24 '22 10:12

Asaph