我已經查看過有關此主題的以前的問題,但我的問題尚未解決。將javascript數組傳遞給servlet
我從javascript傳遞數組到servlet。
JavaScript代碼:
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代碼:
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");
使用上面的代碼我得到消息「行動爲空」。
如果我嘗試
String actions[] = request.getParameterNames("action[]");
我得到語法錯誤:
The method getParameterNames() in the type ServletRequest is not applicable for the arguments (String)
請讓我知道如果有什麼錯誤的代碼。
哪裏是調用這個servlet的HTML或JavaScript代碼? – home
你可以發佈代碼,你如何發送動作數組到servlet ... –