js中直接使用el表达式

来源:互联网 发布:因windows system32 编辑:程序博客网 时间:2024/05/16 04:32

1. JS代码在JSP页面中, 这可以直接使用EL表达式. 如:

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <script type="text/javascript">  
  2.     $(function () {  
  3.         new BacklogOverview("${param.alert}");  
  4.     });  
  5. </script>  

2.JS代码是单独的.js 文件, 通过引入到 JSP中来.这时候可通过提前定义JS变量的形式的解决,如:

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <c:set var="contextPath" value="${pageContext.request.contextPath}" scope="application"/>  
  2.     <script>  
  3.         <%--JS gloable varilible--%>  
  4.         var contextPath = "${contextPath}";  
  5.     </script>  

在JSP页面上定义JS变量 contextPath.

这样在之后引入的JS文件中就可以使用contextPath变量了.

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. //Image setting  
  2. config.filebrowserImageUploadUrl = contextPath + "/ckeditor/upload.htm"; 
0 0
原创粉丝点击