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>
<script type="text/javascript" src="jquery.js" ></script>
<script type="text/javascript" >
$(document).ready(function(){
$("#submit").click(function(){
var t = $("#check").val();
var time = new Date();
$.ajax({
cache:false,
url :'JsonPlugin.action', //后台处理程序
type:'post', //数据发送方式
cache:false,
dataType:'json', //接受数据格式
data:{check:t,t:time}, //要传递的数据
success:update_page //回传函数(这里是函数名)
});
});
//ajax提交
$("#loading").ajaxStart(function(){
$(this).html("<img src=\"loader.gif\"> 正在加载");
alert(new Date());
});
//ajax结束状态
$("#loading").ajaxStop(function(){
$(this).html("");
});
});
function update_page (json ) { //回传函数实体,参数为XMLhttpRequest.responseText
var str= "ISBN="+json.ISBN + ",check:" + json.check + ",title="+json.title
+ ",list=" + json.comments[2];
$("#bookHolder").html(str);
}
</script>
</head>
<body>
<div id="loading"></div>
<input id="check" type="text" >
<input id="submit" type="button" value="Retrieve Book" />
<div id="bookHolder"></div>
</body>
</html>
action代碼:
package tutorial;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;
public class JsonPluginAction extends ActionSupport {
private static final long serialVersionUID = -6784977600668791997L;
private int bookId;
private String title;
private double price;
private List<String> comments;
private transient String secret1;
private String secret2;
private String check ;
@JSON(name="ISBN")
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public List<String> getComments() {
return comments;
}
public void setComments(List<String> comments) {
this.comments = comments;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String execute() throws Exception{
if(check!=null){
System.out.println("check:"+URLEncoder.encode(check,"utf-8"));
}
bookId = 15645912;
title = "Max On 驕傲va";
price = 0.9999d;
comments = new ArrayList<String>(3);
comments.add("It's no bad!");
comments.add("WOW!");
comments.add("No comment!");
secret1 = "You can't see me!";
secret2 = "I am invisible!";
return SUCCESS;
}
public void setCheck(String check) {
this.check = check;
}
public String getCheck() {
return check;
}
}
struts.xml代碼:
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="Struts2_AJAX_DEMO" extends="json-default">
<action name="JsonPlugin" class="tutorial.JsonPluginAction">
<result type="json" />
</action>
</package>
</struts>
分享到:
相关推荐
Jquery+struts2上传图片,制作进度条等示例,还有Jquery+Json+Struts实现Ajax技术,还有图形处理技术等,虽然很少,但都有重点突出,由于我也是学习,所以代码不是很简洁,对想学习交流的朋友非常合适
json+jquery+struts2+hibernate+spring 实现的小型bbs系统,这个提供包 ,很不错的下载后,好好徐希一下吧
struts2 json jquery ajax实现用户登陆及业面跳转
自己整理的jquery+json+struts2异步传输的例子,包括异步提交form,异步传输json对象。
NULL 博文链接:https://gongchangming.iteye.com/blog/421351
1、JSON0.34使用的是struts2附带的struts2-json-plugin-2.1.8.1.jar 2、db是mysql,名字为test,用户名root,密码空 3、com.morningstar.utility.WSUtility为调用WebService的客户端代码,在调用这个WebService返回...
json + struts2 + 80个JQuery 效果 个例子
NULL 博文链接:https://lw671579557.iteye.com/blog/1946083
struts2+spring+hibernate+jquery+json 以前没有做过此类的东西终于有时间来试试 可以方便学习
JEECMS使用目前java主流技术架构:hibernate3+struts2+spring2+freemarker。AJAX使用jquery和json实现。视图层并没有使用传统的JSP技术,而是使用更为专业、灵活、高效freemarker。 数据库使用MYSQL,并可支持orcale...
Struts2 Jquery JSON Struts2 Jquery JSON Struts2 Jquery JSON Struts2 Jquery JSON Struts2 Jquery JSON Struts2 Jquery JSON Struts2 Jquery JSON Struts2 Jquery JSON
jQuery json+struts2 jar包全集
通过jQuery获取表单数据,封装到JSON对象,再把JSON对象转为字符串传到Action,接到数据后,再把JSON字符串变为JSON对象,通过JSON的键,取出数据,通过调用数据库返回数据封装在JSON,打印出数据,然后在客户端接收...
1、将struts2的json插件加入web工程的lib,jsonplugin的下载地址:http://code.google.com/p/jsonplugin/downloads/list
一个简单的struts2+json+jquery 交互的例子,记得把Tomcat依赖加入到工程中
struts+jquery+json+ajax.pdf
一个基于flexigrid+struts2+json+jquery开发的实例,并拓展了一些功能: 1.添加了右键事件(查删改),jqmodal 2.实现了列百分比的显示 3.优化了查询界面
非常全的json各种类型数据处理方法 strut2.3+jquery +ajax+json
Struts1.3+Hibernate3.2+Spring2.5+JQuery1.3
Struts2+JSON+JQuery实现简单的验证; 需要 JDK1.6+ tomcat5.0+ 支持~~~ 不说废话,上源码!!