gpt4 book ai didi

javascript 和 jsp 将 javascript 变量获取到我的 jsp 页面

转载 作者:行者123 更新时间:2023-12-03 09:36:39 28 4
gpt4 key购买 nike

我有我的 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 中使用......

最佳答案

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

类似的东西

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

关于javascript 和 jsp 将 javascript 变量获取到我的 jsp 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31314166/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com