Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何遍历选定的HTML表行并从每行检索数据_Javascript_Java_Jquery_Spring Mvc_Datatables - Fatal编程技术网

Javascript 如何遍历选定的HTML表行并从每行检索数据

Javascript 如何遍历选定的HTML表行并从每行检索数据,javascript,java,jquery,spring-mvc,datatables,Javascript,Java,Jquery,Spring Mvc,Datatables,我使用SpringMVC在jsp上显示从Oracle数据库中选择的数据列表 在表中显示数据的代码如下(使用datatables插件): 在jsp上,使用基本提交按钮处理此提交: <button type="submit" class="btn btn-primary" id="saveLocations" name="saveLocations">Save</button> 保存 我试图做的是检索表中的每个选定行。我知道我必须以某种方式循环遍历这些值,但我真的不确定如

我使用SpringMVC在jsp上显示从Oracle数据库中选择的数据列表

在表中显示数据的代码如下(使用datatables插件):

在jsp上,使用基本提交按钮处理此提交:

<button type="submit" class="btn btn-primary" id="saveLocations" name="saveLocations">Save</button>
保存
我试图做的是检索表中的每个选定行。我知道我必须以某种方式循环遍历这些值,但我真的不确定如何做到这一点

答:返回多个值时,需要使用getParameterValues()。因此,新控制器如下所示:

    String[] values = req.getParameterValues("selectedID");
    for(int i=0;i<values.length;i++)
    {
    System.out.println(values[i]);
    }
String[]values=req.getParameterValues(“selectedID”);
对于(int i=0;隔离
您可以使用下面的代码段,其中
frmexample
是表单的ID

它将遍历表中的所有复选框,并将DOM中不存在的复选框添加为
元素

// Handle form submission event
$('#frm-example').on('submit', function(e){
   var form = this;

   // Iterate over all checkboxes in the table
   table.$('input[type="checkbox"]').each(function(){
      // If checkbox doesn't exist in DOM
      if(!$.contains(document, this)){
         // If checkbox is checked
         if(this.checked){
            // Create a hidden element 
            $(form).append(
               $('<input>')
                  .attr('type', 'hidden')
                  .attr('name', this.name)
                  .val(this.value)
            );
         }
      } 
   });
});
//处理表单提交事件
$('frm示例')。在('submit',函数(e)上{
var form=此;
//迭代表中的所有复选框
表.$('input[type=“checkbox”]”)。每个(函数(){
//如果DOM中不存在复选框
如果(!$包含(文档,本)){
//如果选中复选框
如果(选中此项){
//创建一个隐藏元素
$(表格)。附加(
$('')
.attr('类型','隐藏')
.attr('name',this.name)
.val(此.value)
);
}
} 
});
});
我不是Java专家,但它看起来需要在服务器端使用,而不是。根据手册,只有一个值时应该使用

演示
有关更多详细信息和演示,请参阅。

在发布我的原始问题之前,我实际上在您的网站上看到了这一点。我试图使用它,但我的控制器仍然只返回第一个值。@问号,我不是Java专家,但根据应该在只有一个值的情况下使用。BOOM!!你知道了,谢谢!我只需要制作一个结果的字符串数组,添加一个“for”循环,并打印每个结果。太好了,谢谢!我使用getParameterValues将我的新控制器添加到了我的原始帖子中,如果您想将其添加到您的答案中的话。实际上,使用getParameterValues时甚至不需要javascript。
    String[] values = req.getParameterValues("selectedID");
    for(int i=0;i<values.length;i++)
    {
    System.out.println(values[i]);
    }
// Handle form submission event
$('#frm-example').on('submit', function(e){
   var form = this;

   // Iterate over all checkboxes in the table
   table.$('input[type="checkbox"]').each(function(){
      // If checkbox doesn't exist in DOM
      if(!$.contains(document, this)){
         // If checkbox is checked
         if(this.checked){
            // Create a hidden element 
            $(form).append(
               $('<input>')
                  .attr('type', 'hidden')
                  .attr('name', this.name)
                  .val(this.value)
            );
         }
      } 
   });
});