传递JavaScript数组与Servlet [英] Passing javascript array to servlet

查看:145
本文介绍了传递JavaScript数组与Servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过的SO关于这一主题previous的问题,但我的问题还没有解决。

I have looked previous questions on this topic on SO, but my problem is not solved yet.

我传递数组从JavaScript来的servlet。

I am passing the array from javascript to servlet.

JavaScript的code:

JavaScript Code:

var action = new Array();
function getProtAcionValues(rowNo,columnCount)
{
    for(var j=0;j<columnCount;j++)
    {
        action[j] =  document.getElementById('textActions'+rowNo+''+j).value;
        alert(action[j]);
    }
}

Servlet的code:

Servlet Code:

String actions[] = request.getParameterValues("action[]");
if(actions!=null)
for(int i=0;i<actions.length;i++)
{
    System.out.print(" Action: "+actions);
}
else
    System.out.println("Action is null");

使用上述code我得到消息的行动为空

如果我尝试

String actions[] = request.getParameterNames("action[]");

我收到语法错误:

I am getting Syntax error:

The method getParameterNames() in the type ServletRequest is not applicable for the arguments (String)

请让我知道如果有什么问题在code。

Please let me know if there is something wrong in code.

推荐答案

你可以简单地用数组名获得数组...

you can just simply get the array with the name of the array...

字符串操作[] = request.getParameterValues​​(行动);

这篇关于传递JavaScript数组与Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆