1.客户端编程:jsp页面
<%@ page language="java" contentType="text/html;
charset=UTF-8"

  
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>Insert title
here</title>
</head>
<script type="text/javascript"
src="js/jquery-1.4.2.js"></script>

<script type="text/javascript"
src="js/json2.js"></script>

<body>
<form action="">
<table>
<tr>
<td>名字</td>

<td><input type="text"
id="name"
name="name"/></td>

</tr>
<tr>
<td>年龄</td>

<td><input type="text"
id="age"
name="age"/></td>

</tr>
<tr>
<td><input
type="button" value="提交" onclick="commit();"/>
</td>
</tr>
</table>
<table id="ulist" border="2">
</table>
</form>
</body>
<script type="text/javascript">
function commit(){
  

 $.ajax(
  
   
   
 {type : "post",
  
   
   
 
data:{name: $ ('#name').val(),   
                      age: $ ('#age').val()},
  
   
   
  url : "testJson_testJson.action",
  
   
   
  dataType : "JSON",
  
   
   
  success : callback
  
   
   
   
 }
  
   
   
 );
}
function callback(data){
    var json
=  JSON.parse(data);
  
 alert("fdf");
    var ulist
=    $("#ulist");   
       $.each(json,
function(i,item){
        
ulist.append(
       
"<tr><td>"+item.name+"</td><td>"+item.age+"</td></tr>"

);
  
   
 })
}
</script>
</html>
2.服务端编程:用到sturst2

public class Person {
    private
String name;
    private
String age;
    public
String getName() {
   
    return
name;
    }
    public void
setName(String name) {
   
    this.name =
name;
    }
    public
String getAge() {
   
    return
age;
    }
    public void
setAge(String age) {
   
    this.age =
age;
    }

}

public class TestJsonAction {

private
static final long serialVersionUID = -3571998877536556903L;

public
String testJson() throws Exception {
   
    Person p1 =
new Person();
   
   
p1.setName("nn");
   
   
p1.setAge("11");
   
    Person p2 =
new Person();
   
   
p2.setName("gg");
   
   
p2.setAge("12");
   
    Person p3 =
new Person();
   
   
p3.setName("rr");
   
   
p3.setAge("24");
   
   
List<Person> ulist = new
ArrayList<Person>();
   
   
ulist.add(p1);
   
   
ulist.add(p2);
   
   
ulist.add(p3);
   
    String name
=ServletActionContext.getRequest().getParameter("name");
   
    String age =
ServletActionContext.getRequest().getParameter("age");
   
    Person p4 =
new Person();
   
   
p4.setName(name);
   
   
p4.setAge(age);
   
   
ulist.add(p4);
   
    JSONArray
json = JSONArray.fromObject(ulist);
   
   
ServletActionContext.getResponse().getWriter().print(json);
   
    return
null;
    }

}

一个简单json数据提交实例的更多相关文章

  1. TypeToken 是google提供的一个解析Json数据的类库中一个类

    Type listType = new TypeToken<LinkedList<User>>(){}.getType(); Type是java里的reflect包的Type ...

  2. 【转】c#处理3种json数据的实例

    http://www.jb51.net/article/48027.htm http://json2csharp.chahuo.com/ 网络中数据传输经常是xml或者json,现在做的一个项目之前调 ...

  3. c#处理3种json数据的实例

    网络中数据传输经常是xml或者json,现在做的一个项目之前调其他系统接口都是返回的xml格式,刚刚遇到一个返回json格式数据的接口,通过例子由易到难总结一下处理过程,希望能帮到和我一样开始不会的朋 ...

  4. [WCF REST] 一个简单的REST服务实例

    Get:http://www.cnblogs.com/artech/archive/2012/02/04/wcf-rest-sample.html [01] 一个简单的REST服务实例 [02] We ...

  5. PureMVC和Unity3D的UGUI制作一个简单的员工管理系统实例

    前言: 1.关于PureMVC: MVC框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...

  6. 【安卓开发】一个简单快递查询APP实例的实现摘要

    前言 做毕业设计涉及到安卓开发,决定好好学习安卓开发.在正式做毕业设计之前,有必要先设计和完成一个与毕业设计最终成果相关的demo或者说样例APP.最终毕业设计需要实现的功能包括通过调用PHP端API ...

  7. 一个简单的Android小实例

    原文:一个简单的Android小实例 一.配置环境 1.下载intellij idea15 2.安装Android SDK,通过Android SDK管理器安装或卸载Android平台   3.安装J ...

  8. 一个简单的jQuery插件开发实例

    两年前写的一个简单的jQuery插件开发实例,还是可以看看的: <script type="text/javascript" src="jquery-1.7.2.m ...

  9. spring boot: @Entity @Repository一个简单的数据读存储读取

    spring boot: @Entity @Repository一个简单的数据读存储读取 创建了一个实体类. 如何持久化呢?1.使用@Entity进行实体类的持久化操作,当JPA检测到我们的实体类当中 ...

随机推荐

  1. tcp-client-c++

    #include "stdafx.h" #include <Winsock2.h> #include <iostream> #pragma comment( ...

  2. QQ群里收集的外企iOS开发的笔试题

    一组外企iOS开发的笔试题,您能回答出来吗?从群里收集来的. 1 why can't NSArray contain NSInteger Instance? with which extra step ...

  3. iTween基础之Punch(摇晃)

    一.基础介绍:二.基础属性 原文地址 : http://blog.csdn.net/dingkun520wy/article/details/50828042 一.基础介绍 PunchPosition ...

  4. JAVA SSH 框架介绍

    SSH 为 struts+spring+hibernate 的一个集成框架,是目前较流行的一种JAVA Web应用程序开源框架. Struts Struts是一个基于Sun J2EE平台的MVC框架, ...

  5. mysql federated engine

    mysql)) -> engine=federated -> connection='mysql://root@localhost:3306/t1/t';

  6. 基于AgileEAS.NET企业应用平台实现基于SOA架构的应用整合方案-开篇

    开篇 系统架构的文章,准备在这段时间好好的梳理和整理一下,然后发布基于AgileEAS.NET平台之上的企业级应用架构实践,结合具体的案例来说明AgileEAS.NET平 台之上如何进行系统的逻辑架构 ...

  7. PHP开发框架[流行度排名]

    在PHP开发中,选择合适的框架有助于加快软件开发,节约宝贵的项目时间,让开发者专注于功能的实现上.Sitepoint网站做了一个小的调查,结果显示最流行的PHP框架前三甲为:Laravel.Phalc ...

  8. Unity3D脚本中文系列教程(十四)

    http://dong2008hong.blog.163.com/blog/static/469688272014032134394/ WWWFrom 类Unity3D脚本中文系列教程(十三)辅助类. ...

  9. Building Plugins for iOS

    This page describes Native Code Plugins for the iOS platform. Building an Application with a Native ...

  10. 【设计模式六大原则5】迪米特法则(Law Of Demeter)

      定义:一个对象应该对其他对象保持最少的了解. 问题由来:类与类之间的关系越密切,耦合度越大,当一个类发生改变时,对另一个类的影响也越大. 解决方案:尽量降低类与类之间的耦合. 自从我们接触编程开始 ...