Scriptlet in js

前端 未结 2 536
终归单人心
终归单人心 2021-01-27 19:55

i have a jsp page... i am adding some content to page dynamically depending upon request parameters (an array will be returned by request) based on this i have to create a drop

相关标签:
2条回答
  • 2021-01-27 20:37

    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 = "";
    } 
    
    • Also See

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

    0 讨论(0)
  • 2021-01-27 20:50

    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.

    0 讨论(0)
提交回复
热议问题