Using EL in JS

in two cases

 

1. The JS code is in the JSP page, which can directly use EL expressions. For example:

 

[html]  view plain copy  
 
 print ? View code snippets on CODE Derive to my code slice
  1. <scripttype="text/javascript">   
  2.     $(function () {  
  3.         new BacklogOverview("${param.alert}");  
  4.     });  
  5. </script>  



 

2. JS code is a separate .js file, which is introduced into JSP. At this time, it can be solved by defining JS variables in advance, such as:

 

[html]  view plain copy  
 
 print ? View code snippets on CODE Derive to my code slice
  1. <c:setvar="contextPath"value="${pageContext.request.contextPath}"scope="application"/>     
  2.     <script>  
  3.         <%--JS gloable varilible--%>  
  4.         var contextPath = "${contextPath}";  
  5.     </script>  


Define the JS variable contextPath on the JSP page.

 

In this way, the contextPath variable can be used in the JS file introduced later.

 

[html]  view plain copy  
 
 print ? View code snippets on CODE Derive to my code slice
  1. //Image setting  
  2. config.filebrowserImageUploadUrl = contextPath + "/ckeditor/upload.htm";  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327057470&siteId=291194637