早上好,我從JSP發送一個java腳本數組到servlet使用jQuery.post()
但這裏的問題是它執行動作時拋出java.lang.NullPointerException at servlets.DeleteServlet.doPost(DeleteServlet.java:45)
這裏是java-script方法發送數組到servlet:傳遞javascript數組到servlet問題
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
var myIdsArray = new Array;
function getCarId(tableID) { // these methods fills the array with values
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
if (rowCount <= 2) {
alert("Cannot delete all the rows.");
break;
}
myIdsArray.push(table.rows[i].cells[1].innerHTML);
}
}
sendArrayToServer();
} catch (e) {
alert(e);
}
}
function sendArrayToServer() {
alert("Called");
$.post('DeleteServlet', {
arrayData : myIdsArray,
mode : "insert"
});
,這裏是我的servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String[] arrayData=request.getParameterValues("arrayData");
PrintWriter out=response.getWriter();
for (String string : arrayData) { // line 45
out.println(string);
}
DeleteServlet.java中的第45行在哪裏? – 2013-02-28 01:46:09
早上好?這裏是22.42!當你在js中使用console.log(myIdsArray)時,你會得到什麼? – martriay 2013-02-28 01:46:45