How to prevent interpretation of $ in JSP to create jQuery templates

I have a page generated with data from both the backend and the front. The front end uses a jquery template, and the page itself is written in JSP, and there is a conflict using the $ sign:

<script type="text/javascript">
   ${title}
</script>

For example, I want the above code to be interpreted by the interface, but the JSP translates to something else. How to prevent this?

thank

Oliver

+3
source share
5 answers

Add this at the top of the page:

<%@ page isELIgnored="true" %>

It should only be on the page that defines the template. Include this page from the main page if you want to use EL in it.

+6
source

Put a backslash in front of the dollar sign and this will not be interpreted as JSP EL.

\${title}

, ${1+1} 2 \${1+1} ${1+1}.

, Jared.

+11

You can try the following for problematic lines

out.print("${title}")
+3
source

Why not wrap them between jsp: text or move all of your template code in a .js file, if possible.

0
source

also you can use this

<%="${name}"%>
0
source

Source: https://habr.com/ru/post/1793147/


All Articles