jQuery Template Markup and JSP Expression Language (EL)

5 篇文章 0 订阅

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值