Javascript file not having access to jstl

I have jstl code inside a javascript file that I include in my jsp page. The problem is that when I write my jstl code inside a script inside a jsp page, it works fine. but when I write the same code in a separate js file, jstl code doesn't work at all. Anyway, can I get around this? Any help would be greatly 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); }); 
+6
source share
1 answer

JSPs are interpreted by the server before outputting to the browser, so your tags are interpreted before serving them in the browser. In a standard JS configuration, files are not interpreted by the server, but simply transferred to the client as plain text.

If you want to dynamically create JS with JSP (as in your example), you need to make the server interpret the file before serving it to the client. The easiest way is to place the contents of the JS in a JSP file. Then on the html page, a script is included with the script tag and the src attribute is equal to your.jsp, for example. <script src = "script.jsp" </script>

+7
source

Source: https://habr.com/ru/post/946447/


All Articles