日期:2014-05-17  浏览次数:20604 次

jquery发送json,servlet接收不到
SSH2项目中用jquery发送json,Action中接收不到。。
js代码:
$.ajax({
type:'post',
url:'/test.do',
data:{'name':'lin'},
datatype:'json',
success:function(result){
alert(result);
}
});
action中的java代码:

StringBuffer json = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
json.append(line);
System.out.println("getJSON:" + line);
}
} catch (Exception e) {
System.out.println(e.toString());
}
tomcat控制台输出接收为空

------解决方案--------------------
怎么我用jsp+servlet测试的是正确的,控制台输出了 getJSON:name=lin
你的url没写错吧,有没有进入到后台呀
------解决方案--------------------
StringBuffer json = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
json.append(line);
System.out.println("getJSON:" + line);
}
} catch (Exception e) {
System.out.println(e.toString());
}