JS中使用EL

分两种情况

 

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";  

猜你喜欢

转载自hahalovenini.iteye.com/blog/2346112