`
lan13217
  • 浏览: 498021 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

jQuery Template Markup and JSP Expression Language (EL)

 
阅读更多

Maybe it is "great minds think alike"; both JSP Expression Language (EL) and jQuery Template use the 

${}

as variable placeholders and evaluate it. Since JSP will be complied at server side first, any ${} in JSP file will be evaluated first, even it means for jQuery template. When your result page return to user's browser and jQuery template energy try to complie the template, you will find your ${} had been changed to variable value you store in Page, Session or Application context in your sever side.

Therefore, we need to escape ${} in JSP page which means for jQuery template or turn off Expression Language evaluate. There are two options:

1. escapse ${} in JSP page


In EL, you can use character ${'${'}} to be escapted as ${}

for example, 
<script id="clientTemplate" type="text/html">
<li><a href="clients/${id}">${name}</a></li>
</script>

need to be escaped as:


<script id="clientTemplate" type="text/html">
<li><a href="clients/${'${'}id}">${'${'}name}</a></li>
</script>

This approach is good when your template is simple. 

2. save jQuery template as separated file and disable its EL evaluation


if you have a lot of jQuery templates, it's better to extract them out to a seperated file.
<%@ page isELIgnored="true" %>
<script id="clientTemplate" type="text/html">
<li><a href="clients/${id}">${name}</a></li>
</script>
<script id="anotherTemplate" type="text/html">
<li><a href="clients/${id}">${name}</a></li>
</script>
Then include this file in your JSP pages need template:
<jsp:include page="jqTemplate.jsp"></jsp:include>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics