Is it possible to use jstl inside javascript?
I’m tying to set <c:set var="abc" value="yes"/>
and then later access this value in html and execute some code. My problem is the c:set is executing always even if the javascript condition is false.
<script type="text/javascript">
var v1 = false;
<c:set var"abc" value="yes"/>
if(v1){
<c:set var"abc" value="no"/>
}
</script>
In the above code, even if v1 is false ‘no’ is setting to abc.
There is no meaning to the idea of being “inside Javascript” when you’re talking about server-side JSP interpretation. There’s just no such thing as Javascript as far as that domain is concerned.
Thus, yes, it’s possible, if you mean that you want to do something like
Note that you have to be careful with quoting and special characters. The JSTL
fn:escapeXml()function is useless when you’re interpolating a JSP variable into a part of the page that will be interpreted as Javascript source by the browser. You can either use a JSON library to encode your strings, or you can write your own EL function to do it.