jstl code in javascript
Hello
i am converting jsp pages with java snippet code with these tags <%%> TO jstl tags.
in our old page we have a JS function like this..
<script language="JavaScript">
var cal5<%=i%><%=provNum%> ....
</script>
but when i replace <% tags wtih <c:out in that function name i dont think its working.
does anyone know if we can use jstl tags in naming JS functions.
This is done because we have a loop and we have bunch of JS calendar objects specific to each date checkbox.
# 1
any help?
just wondering if there is any way JS will understand jstl tags?
<script>
var cal5<c:out value="${check}"/> = test;
</script>
doesnt work but
<script>
var cal5<%=check%> = test;
</script>
works fine
# 2
JSTL / scriptlet code - neither should matter to the javascript. Both are evaluated before javascript even runs.
Remember that JSP/Java is on the Server side. What actually gets sent to your browser is an html page (after all the java code has run). Viewing source in the browser will show you the html generated by your jsp.
So why is it not working?
<%= check %> and ${check} are not the same things.
${check} translates approximately as <%= pageContext.findAttribute("check") %>
So while the <c:out> tag is probably working, it probably isn't using the check value that you think it should
Solution: use c:set to set the value as a JSTL variable rather than a scriptlet variable.