Scriptlet in js

核能气质少年 提交于 2019-12-02 07:42:11
Jigar Joshi

Yes you can have something like this

function addCombo() {
    var textb = document.getElementById("txtCombo");
    var combo = document.getElementById("combo");

    var option = document.createElement("option");
    <c:forEach var="state" items="${stateList}" varStatus="status">  
    option.text = "${state}";
    option.value = "${state}";
    try {
        combo.add(option, null); //Standard
    }catch(error) {
        combo.add(option); // IE only
    }
    </c:forEach>
    textb.value = "";
} 

Note: I haven't tested this code , this is just a demonstration

If the javascript is inline or declared in the same jsp page, there is no problem. Something like:

<script type="text/javascript">
var foo = '${foo}'; // or <%= foo => if you like
</script>

If it is in a separate .js file, then you should serve the .js file through a special servlet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!