Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript file not accessing jstl

I have my jstl code inside a javascript file that i am including inside my jsp page. The problem I have is that when i write my jstl code inside a script inside the jsp page it is working fine. but when i write the same code in a separate js file, the jstl code does not work at all. Is there anyway I can get around this? Any help would be appreciated. Here is my code below. Thanks

$("img[name='cancel']").hover(function(){
      var src = "<c:url value='/images/stop.ico'/>";
      $(this).attr("src",src);
  },function(){
      var src = "<c:url value='/images/gtk_close.ico'/>";
      $(this).attr("src",src);
  });
like image 1000
Katakam Nikhil Avatar asked Jun 03 '13 19:06

Katakam Nikhil


1 Answers

JSPs are interpreted by server before producing output to the browser, therefore your tags are being interpreted before being served to the browser. With standard configuration JS files are are not interpreted by the server, just passed through to the client as plain text.

If you want to produce JS dynamically with JSP (as in your example), you need to make server to interpret file before serving it to the client. The easiest way it would be to put content of your JS into JSP file. Then on the html page include script with the script tag and attribute src equals your.jsp, e.g. <script src="script.jsp"></script>

like image 52
Beata Gellner Avatar answered Sep 28 '22 09:09

Beata Gellner