How can the Javascript engine interpret the below code?
I thought just the JSTL tags embedded within html are interpreted?
<script type="text/javascript">
<c:choose>
<c:when test="${fn:contains(val, 'test')}">
alert('test);
</c:when>
</c:choose>
</script>
The JavaScript engine doesn’t interpret the JSTL because it doesn’t see it. The JSTL is handled server-side before the response is sent to the browser. The JSTL/Java side of things only cares about JSTL/Java code – everything else is basically passed through in the response as-is. So it doesn’t matter if you include a script element or JavaScript or other html elements, all will become part of the response.
Within your browser if you select “View Page Source” you’ll see the code as received by the browser – you’ll note it doesn’t include any JSTL.
In your specific example, the response will – depending on the result of the JSTL test – either include a script element with that one line
alert('test')or just an empty script element.