JqueryServlet.java
package com.fayhong.util;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.fayhong.service.basicdata.BasicDataService;
public class JqueryServlet extends HttpServlet {
public BasicDataService basicDataService;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
doPost(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
basicDataService=(BasicDataService)wac.getBean("basicDataService");
resp.setContentType("text/html;charset=UTF-8");
resp.setHeader("Cache-Control", "no-cache");
JSONObject json = new JSONObject();
List list=basicDataService.findCountry(null, null);
try{
JSONArray members = new JSONArray().fromObject(list);
json.put("country", members);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println(json.toString());
resp.getWriter().write(json.toString());
}
}
jqueryjson.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>JSON</title>
<script src="scripts/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="scripts/jquery/json.js" type="text/javascript"></script>
<script>
$(document).ready(function (){
var query="test";
$.getJSON("jquery",null,function call(data){ wirteHtml(data);})
});
function wirteHtml(data){
$.each(data.country,function(idx,item){
if(idx==0){
return true;//同countinue,返回false同break
}
alert(item.englishName);
});
alert(data.country.length);
alert(data.country[0].englishName);
}
</script>
</head>
<body>
</body>
</html>
分享到:
相关推荐
SSH +jquery+json做的Ajax级联操作 简练清晰 容易理解 完全可以拷贝引用
struts2+spring+hibernate+jquery+json 以前没有做过此类的东西终于有时间来试试 可以方便学习
Springmvc+maven+ajax+jquery+json+mybatis做的登录,注册,增删改查详细注释,大家可以来一下,看看对自己有没有帮助哈,这是我自己一点点的打的,采用MyEclipse 10运行出来.并且付有sql脚本.可直接导入运行.并且经本人...
Ajax无刷新分页(jQuery+Json) 做了一个用jQuery来实现的用户控件,VS2008+Access jQuery+ashx+JSON 用ashx来接收请求,数据格式为JSON 实现了批量(选择)操作,编辑接口(反回两个值给用户进行自定义操作) 删除,...
jQuery+Json 实现Ajax无刷新分类管理实例演示 基于jquery+json实现的网站后台管理中无刷新的分类管理功能演示,如上图演示所示,可无刷新添加一个分类、在动画弹出的对话框中输入分类名称即可实现保存,同进还可无...
Ajax无刷新分页(jQuery+Json) 做了一个用jQuery来实现的用户控件,VS2008+Access 只用来玩玩.所以就用Access数据库了 jQuery+ashx+JSON 用ashx来接收请求,数据格式为JSON 实现了批量(选择)操作,编辑接口(反回...
Java+Servlet+Jquery+Json基础示例
ajax,jquery,json一个页面实现Ajax效果的增删改查-JQuery+Json版.zip
Struts1.3+Hibernate3.2+Spring2.5+JQuery1.3
jquery+json的无刷新分页 jquery+json的无刷新分页 jquery+json的无刷新分页 jquery+json的无刷新分页
Jquery+JSON+WebService交互
jquery+json 实现页面无刷新列表 分页
jquery+json 无刷新分页,这个是用VS2008+SQL2000开发的实例
基于jQuery+JSON的省市联动效果
Jquery+JSON+REST WCF DEMO
1、将struts2的json插件加入web工程的lib,jsonplugin的下载地址:http://code.google.com/p/jsonplugin/downloads/list
ssh2+ajax+jquery+json验证用户名是否存在
ext3.0+highcharts+ext时间日期控件+jquery+json