Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dollar curly brackets issue in JSP and Jquery

In JSP, I notice that I can't render ${} into HTML. After the page is rendered, the HTML page will not show ${} anymore. In my understanding, ${} is part of java syntax.

Is there any approach to render this into HTML? Currently, I use print "${}" as a string so I can render this on my HTML. I need this symbol to be rendered as it is so later I can grab this symbol using jquery. (FYI: I'm using jquery template)

Thanks in advance

like image 210
William Calvin Avatar asked Jan 17 '23 02:01

William Calvin


2 Answers

\${this is not an EL expression}

Escape the expression with \ if it appears in a JSP template.

From the JSP EL 2.2 specification:

To generate literal values that include the character sequence ${ or #{, the developer can choose to use a composite expression as shown here:

${'${'}exprA}
#{'#{'}exprB}

The resulting values would then be the strings ${exprA} and #{exprB}.

Alternatively, the escape characters \$ and \# can be used to escape what would otherwise be treated as an eval-expression. Given the literal-expressions:

\${exprA}
\#{exprB}
like image 102
McDowell Avatar answered Jan 20 '23 04:01

McDowell


You can use \${expression}. If you are not using EL in that JSP page. then you can use
<%@ page isELIgnored ="true" %>.

I would recommend you to use \${expression} and use the EL in other part of JSP. EL is very powerful and very helpful.

~Rajiv

like image 35
Rajiv Karambalkar Avatar answered Jan 20 '23 04:01

Rajiv Karambalkar