开发者

How to prevent $ interpretation in JSP to make jQuery templates work

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

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

For example, I want the above code to be interpreted by front end, but JSP is开发者_StackOverflow社区 translating to something else. How do I prevent this from happening?

thanks

Oliver


Put backslash before dollar sign and it won't be interpreted as JSP EL.

\${title}

So, ${1+1} prints 2 and \${1+1} prints ${1+1}.

Otherwise, you can do what Jared says.


Add this to the top of the page:

<%@ page isELIgnored="true" %>

This should only be in the page which defines the template. Include that page from the main page, if you want to use EL in it.


You could try using the following for any problematic lines

out.print("${title}")


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


also you can use this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜