【问题标题】:javascript and jsp to get the javascript variable in to my jsp pagejavascript 和 jsp 将 javascript 变量放入我的 jsp 页面
【发布时间】:2015-07-09 18:44:16
【问题描述】:

我有我的 javascript 变量 ass 名称数组,我必须将此选定的值打印到我的 jsp 页面中。

这是我的示例代码(例如):

var namesArray = [];
var checkBoxes = document.querySelectorAll('input[type=checkbox]');
for(var i = 0; i < checkBoxes.length; i++) {
    checkBoxes[i].addEventListener('change', function() {
     if(this.checked){
            console.log(this.value);
namesArray.push(this.value);
console.log(namesArray);
                }
    });
}

告诉我如何在我的 jsp 中获取这个 var 并在 session 中使用......

【问题讨论】:

    标签: javascript arrays jsp session


    【解决方案1】:

    您可以在提交时通过查询字符串将数组传递给servlet,并可以使用request.getParameterValues获取servlet中的值

    类似

    String names[]=  request.getParameterValues("namesArray")
    

    【讨论】:

    • 没有提交按钮我可以从 javascript 获取值到我的字符串名称[]
    • 如果你不想提交整个表单..使用 ajax。
    • 你当然可以,但我对 ajax 了解不多,你可以参考这个例子的任何链接,或者如果你有例子发布它
    猜你喜欢
    • 2015-05-02
    • 1970-01-01
    • 2011-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 2012-08-01
    • 2013-07-17
    相关资源
    最近更新 更多