How to do the console.log for EL expression in JS file
jQuery(document).ready(function() {
$('.js-bbCheckbox').click(function(event) {
var bbck = '${tagOne}';
console.log (bbck);
console.log (${tagTwo});
});
How to do the console.log for EL expression in JS file
jQuery(document).ready(function() {
$('.js-bbCheckbox').click(function(event) {
var bbck = '${tagOne}';
console.log (bbck);
console.log (${tagTwo});
});
To start, you need to understand that JSP (and JSTL and EL) basically produces HTML (and CSS and JS) code. It doesn't run in sync with JavaScript code. If you rightclick the JSP page in webbrowser and do View Source then you'll see it.
I think that your concrete problem is caused because the ${tagTwo}
returns a plain vanilla string which is in turn by JS been interpreted as a variable name, because it isn't been enclosed in quotes.
You need to let JSP print a fullworthy JS string instead of a variable name.
console.log('${tagTwo}');
@Shoaib Ud-Din, if you don't mind a little inline code, this should work with any included .js file that is loaded after this in the DOM:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<c:set var="tagOne" value="Hello World" scope="session" />
<script>
var bbck = "<c:out value="${tagOne}" />";
console.info("<c:out value="${tagOne}" />");
</script>