首先 我要说 very 简单
两个事儿
2、第二部 是servlet 中的写法, 记住要写在 dopost方法中
首先把该定义的东西都定义好
- response.setContentType("text/html");
- response.setCharacterEncoding("utf-8");//这里是转码
- request.setCharacterEncoding("utf-8");//这里是转码 (如果还是乱码,请检查此项目的编码格式,要改成UTF-8)
- //以上是发送到客户端的相应类型
- PrintWriter out = response.getWriter();//定义一个 out(用于写回去东西)
- JSONArray array = new JSONArray(); //定义 集合
- JSONObject filejson = new JSONObject(); //定义容器
- filejson.put("array",array);//将数组存入容器
- out.print(filejson);//返回到jsp页面
- out.flush();//清空缓存
- out.close();//关闭 out
这样一来 在前台的 success 中 可以找到 返回的内容 , 你可以尝试 打印下 json.array 就是你传过来的数组
很简单吧