日期:2014-05-17 浏览次数:20870 次
$('#but_json_json').click(function(){
var j ={"name":"王","password":123456};
$.ajax(
{
url:"servlet/JsonObject", //访问路径
type:"POST", //访问方式
data:j, //传入服务端的数据
dataType:"json",
contentType:"application/json;charset=utf-8",
success : function(data){
alert(data);
alert(data.name);
alert(data.password);
}
}
);
});
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String user = request.getParameter("j");
String name = request.getParameter("name");
String password = request.getParameter("password");
System.out.println(user);
//JSON对象
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("password", password).accumulate("name", "www");
response.setContentType("application/json");
response.getWriter().write(jsonObject.toString());
}
String name = request.getParameter("name");
String password = request.getParameter("password");