4
I’m trying to define the value of a variable within a tag script
with JSP expression language. I tried this to check that the value was not empty:
<c:if test="${!empty newsletter.id}">
<script>
$(function(){
alert("Entrou no 'if'");
})
</script>
</c:if>
And it worked, the Alert was displayed normally (then the attribute newsletter.id
is not empty). I then tried to set the variable’s value like this:
<c:if test="${!empty newsletter.id}">
<script>
$(function(){
var foo = ${newsletter.content}; /* aqui... */
alert(foo);
});
</script>
</c:if>
And that’s it, the Alert stopped being displayed. I even thought it was something because of the syntax ${...}
with the jQuery $(...)
and tried so:
<c:if test="${!empty newsletter.id}">
<script>
var foo = ${newsletter.content}; /* tentei fora do document.ready(...) */
$(function(){
alert(foo);
});
</script>
</c:if>
The Alert.
The problem is when assigning the value of newsletter.content
for the variable foo
in Javascript. How do I assign a value from a JSP variable to a variable within the tag script
?