[code="java"]
//前台
var b ="{'name':'jack','sex':'men','age':23}";
var url="a.jsp";
createXMLHttpRequest();
xmlHttp.open("post",url,true);
xmlHttp.send("url="+b);
//后台
String jsonString= request.getParameter("url");
System.out.println(jsonString);
//可是获取不到、、
[/code]
1)get:请求参数是作为一个查询字符串附加到URL上的
2)post:请求参数是在http标题的一个不同部分(名为entity body)传输的,这一部分用来传输表单信息,因此必须将
Content-type设置为:application/x-www-form-urlencoded。
所以你的前台代码应该修改为
[code="java"]
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send("url="+b);
[/code]
这样改呢你能就能在后台获取到相应的值了。