各位前辈:
我在用ajax post方式时候出现了问题,求助。
问题描述如下:
前台:
xmlHttp = createXMLHttpRequest();
var postString=[{customerId: "1 "},{customerId: "2 "}];
var url = "/servlet/com.sino.ies.inv.maintenance.servlet.ItemVarifyServlet " ;
xmlHttp.onreadystatechange = doVerifySegment10;
xmlHttp.open( 'POST ', url, true);
xmlHttp.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");
xmlHttp.send(postString);
后台:
StringBuffer json = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
System.out.println(reader.readLine()); //始终为NULL
while ((line = reader.readLine()) != null) {
json.append(line);
}
}
catch (Exception e) {
System.out.println( "Error reading JSON string: " + e.toString());
}
System.out.println(json.toString());
return unescape(json.toString());
问题就是:用上述方法去取post的数据,却始终取不到,,,各位前辈帮我看看,谢谢大家了。
------解决方案--------------------
后台代码写在servlet的哪个方法里的,如果是post提交,要在dopost方法里面吧