jsp里的${}和jquery template的${} 怎么样转义

来源:互联网 发布:个性地图制作软件 编辑:程序博客网 时间:2024/04/30 07:34

http://www.infoq.com/cn/news/2010/10/jQuery-Template 

http://api.jquery.com/category/plugins/templates/

ms发布的jquery模板插件
在这个插件里他使用的变量占位符和jsp的el表达式用的是一样的${}, 所以在用jsp作为服务器端的输出时要进行转义, 不然jsp会把原本是属于jquery模板插件的变量也进行了替换. 以下介绍两种方式


1. escapse ${} in JSP page

[html] view plaincopyprint?
  1. <script id="clientTemplate" type="text/html">  
  2. <li><a href="clients/${id}">${name}</a></li>  
  3. </script>  

进行转义后

[html] view plaincopyprint?
  1. <script id="clientTemplate" type="text/html">  
  2. <li><a href="clients/${'${'}id}">${'${'}name}</a></li>  
  3. </script>  

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. 不使用el表达式

[html] view plaincopyprint?
  1. <%@ page isELIgnored="true" %>  
  2. <script id="clientTemplate" type="text/html">  
  3. <li><a href="clients/${id}">${name}</a></li>  
  4. </script>  
  5. <script id="anotherTemplate" type="text/html">  
  6. <li><a href="clients/${id}">${name}</a></li>  
  7. </script>  

Then include this file in your JSP pages need template:

[html] view plaincopyprint?
  1. <jsp:include page="jqTemplate.jsp"></jsp:include>  

http://www.infoq.com/cn/news/2010/10/DataLink-jQuery  Data Link:jQuery的数据绑定插件


http://code.google.com/p/jquery-utils/  jquery 工具集, 包含字符串格式化处理, cookie, 数组, 国际化处理.

原创粉丝点击