In Plain Old JSP
<script>
var someText = "<%= myBean.getText() %>";
</script>
Using EL (Expression Language)
<script>
var someText = "${myBean.text}";
</script>
Using Struts
<script>
var someText = '<bean:write name="myBean" property="text" />';
</script>
Using JSTL
<script>
var someText = '<c:out value="${myBean.text}" />';
</script>
In essence, it's possible to populate Javascript objects from JSP. Don't forget that scriptlets and tags are just rendered back as HTML/XHTML, so JS cannot talk to tags and vice-versa.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…