简体   繁体   English

JSP和Jquery中的美元大括号问题

[英]dollar curly brackets issue in JSP and Jquery

In JSP, I notice that I can't render ${} into HTML. 在JSP中,我注意到我无法将$ {}呈现为HTML。 After the page is rendered, the HTML page will not show ${} anymore. 呈现页面后,HTML页面将不再显示$ {}。 In my understanding, ${} is part of java syntax. 根据我的理解,$ {}是java语法的一部分。

Is there any approach to render this into HTML? 有没有办法将其呈现为HTML? Currently, I use print "${}" as a string so I can render this on my HTML. 目前,我使用print“$ {}”作为字符串,因此我可以在我的HTML上呈现它。 I need this symbol to be rendered as it is so later I can grab this symbol using jquery. 我需要渲染这个符号,因为它是以后我可以使用jquery获取此符号。 (FYI: I'm using jquery template) (仅供参考:我正在使用jquery模板)

Thanks in advance 提前致谢

\${this is not an EL expression}

Escape the expression with \\ if it appears in a JSP template. 如果表达式出现在JSP模板中,请使用\\转义表达式。

From the JSP EL 2.2 specification : JSP EL 2.2规范

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} . 结果值将是字符串${exprA}#{exprB}

Alternatively, the escape characters \\$ and \\# can be used to escape what would otherwise be treated as an eval-expression. 或者,转义字符\\$\\#可用于转义否则将被视为eval-expression的内容。 Given the literal-expressions: 鉴于文字表达式:

 \\${exprA} \\#{exprB} 

You can use \\${expression}. 您可以使用\\ $ {expression}。 If you are not using EL in that JSP page. 如果您没有在该JSP页面中使用EL。 then you can use 然后你可以使用
<%@ page isELIgnored ="true" %>. <%@ page isELIgnored =“true”%>。

I would recommend you to use \\${expression} and use the EL in other part of JSP. 我建议你使用\\ $ {expression}并在JSP的其他部分使用EL。 EL is very powerful and very helpful. EL非常强大且非常有用。

~Rajiv 〜拉吉夫

将此行放在JSP的顶部。

<%@ page isELIgnored ="true" %>

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

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