我想将数组作为请求参数传递给 servlet,如何发送
$.ajax({
type: "POST",
url: "${pageContext.request.contextPath}/MyServlet",
data: params,
success: function(data){
closeMe();
},
error: function(jqXHR, textStatus, errorThrown) {
alert(errorThrown)
}
}); // end of $.ajax()
$("#savebtn").click(function(e) {
var username = $("#username").val();
var password = $("#password").val();
var checkIP = $("#chkIP").is(":checked");
var params = {
action : 'add',
username : username,
password : password,
checkIP : checkIP,
};
if(checkIP){
var ipList = $("#ipaddress").val();
var ip = ipList.split(',');
params['ipList'] = ip
}
});
html
<tr>
<td>Check IP</td>
<td><input type="checkbox" name="chkIP" id="chkIP"></td>
</tr>
<tr>
<td>IP List</td>
<td><textarea id="ipaddress"></textarea></td>
</tr>
例如 id 用户输入122.112.122.45,122.112.122.46,....N
textarea 那么如何在 servlet 中检索它并存储在 db 中?