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);
});
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With