早上好,我正在使用从 JSP 向 servlet 发送一个 java-script 数组,jQuery.post()
但这里的问题是它java.lang.NullPointerException
at servlets.DeleteServlet.doPost(DeleteServlet.java:45)
在执行操作时抛出了一个将数组发送到 servlet 的 java-script 方法:
<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);
}