admin管理员组文章数量:1201570
${}
is being used by both JSP and JS, so what's happening is that the ${}
in the JS template literals are being interpreted and removed before being compiled into servlets.
Is there a way I can tell Java to ignore ${}
without completely turning the feature off with isELIgnored
attribute?
const subject = 'world';
let greet = `hello ${subject}!`
turns into the following in the browser
const subject = 'world';
let greet = `hello !`
Here's the best I've come up with, really not digging how ugly it is though:
<c:out value="var body = `pq_country=${country}&pq_population=${population}`;"
escapeXml='false'/>
${}
is being used by both JSP and JS, so what's happening is that the ${}
in the JS template literals are being interpreted and removed before being compiled into servlets.
Is there a way I can tell Java to ignore ${}
without completely turning the feature off with isELIgnored
attribute?
const subject = 'world';
let greet = `hello ${subject}!`
turns into the following in the browser
const subject = 'world';
let greet = `hello !`
Here's the best I've come up with, really not digging how ugly it is though:
<c:out value="var body = `pq_country=${country}&pq_population=${population}`;"
escapeXml='false'/>
Share
Improve this question
edited May 19, 2024 at 20:45
informatik01
16.4k11 gold badges78 silver badges108 bronze badges
asked Aug 30, 2016 at 13:46
Mark CMark C
2152 silver badges7 bronze badges
4
- Just out of curiosity, why are you using back-ticks? – px06 Commented Aug 30, 2016 at 13:53
- ES6 only substitutes these values when you use backticks as the delimiter. Have you tried using simple apostrophes? – skreborn Commented Aug 30, 2016 at 13:53
- 3 Just write JS code in its own JS file instead of mixing with HTML source. That has been the "best practice" for ages. – BalusC Commented Aug 30, 2016 at 18:30
- It is different to write JS in its own file for "best practice" and different for writing because you don't have any choice. Too bad that this conflict cannot be solved in a better way. – Georgios Syngouroglou Commented Apr 2, 2020 at 7:33
2 Answers
Reset to default 20You can put a backslash in front of the ${}
so JSP ignores it (found out through this article by David Ford).
const subject = 'world';
let greet = `hello \${subject}!`
You have to move the JS code to the function inside the external file or script
tag, it would be the best way to solve conflict of jsp with JS syntax.
本文标签: javascript template literal (ES2015) conflict with JSP Expression Language syntaxStack Overflow
版权声明:本文标题:javascript - ${} template literal (ES2015) conflict with JSP Expression Language syntax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738564918a2099957.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论