ajax 用post方式传输json,后台java用reader.readLine()却为NULL,求助

fengke86 2007-04-21 09:35:48
各位前辈:
我在用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的数据,却始终取不到,,,各位前辈帮我看看,谢谢大家了。
...全文
813 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
shen087395 2012-04-10
  • 打赏
  • 举报
回复
struts主控器已经读取了
而request.getReader()方法只能调用一次
类似于指针下移
是不可逆的
所以你再调用request.getReader()方法读到的就是null了
yqayaoyao 2007-04-28
  • 打赏
  • 举报
回复
up

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧