Search code examples
javascriptjavajspecmascript-6el

${} template literal (ES2015) conflict with JSP Expression Language 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 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'/>

Solution

  • 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.