Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

${} template literal (ES2015) conflict with JSP EL syntax

${} is being used by both JSP and JS, so what's happening is that the ${} in the JS template literals are being interpreted and remove before being compiled into servlets. Is there a way I can tell Java to ignore ${} without completely turning the feature off with isELIgnored?

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'/>
like image 240
Mark C Avatar asked Aug 30 '16 13:08

Mark C


2 Answers

You 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}!`
like image 129
fenix.shadow Avatar answered Nov 10 '22 17:11

fenix.shadow


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.

like image 4
uladzimir Avatar answered Nov 10 '22 16:11

uladzimir