Ajax小例子

package jquery.getstart;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class AutoCompleteAction extends ActionSupport {

 /**
  *
  */
 private static final long serialVersionUID = 1L;

 private String queryString;

 public String getQueryString() {
  return queryString;
 }

 public void setQueryString(String queryString) {
  this.queryString = queryString;
 }
 
 public List<ProvinceJsonBean> getResults(){
  return new ArrayList<ProvinceJsonBean>(){
  {
  ProvinceJsonBean jsonBean=new ProvinceJsonBean();
  jsonBean.setText("北京");
  Province province=new Province();
  province.setId("1");
  province.setName("北京");
  jsonBean.setJson(province);
  this.add(jsonBean);
  }
  };
 }

 public String query() {
  return SUCCESS;
 }

 public static class ProvinceJsonBean{
  private String text;
  private Province json;
  public String getText() {
  return text;
  }
  public void setText(String text) {
  this.text = text;
  }
  public Province getJson() {
  return json;
  }
  public void setJson(Province json) {
  this.json = json;
  }
 }

}


 

代码存放 http://svn.w18.net/svn/junfordemo/trunk/ssh_jquery

我的代码 实现了城市的查找

<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jQuery入门</title>
<link href="css/james.css" type="text/css" rel="stylesheet"/>
<link href="css/default.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.james.js"></script>
<script type="text/javascript">  
var id;
$(document).ready(function() {
  $("#orderedlist").addClass("red");
  });
$(document).ready(function() {
  $("#orderedlist > li").addClass("blue");
  });  
$(document).ready(function() {
  $("#orderedlist li").hover(function() {
  $(this).addClass("blue");
  },function(){
  $(this).removeClass("blue");
  });
});  
$(document).ready(function() {
  $("#orderedlist li:last").hover(function() {
  $(this).addClass("blue");
  },function(){
  $(this).removeClass("blue");
  });
});  
$(document).ready(function() {
  $('#faq').find('dd').hide().end().find('dt').click(function() {
  $(this).next().slideToggle();
  });
});
$(document).ready(function() {
  $("#province").james("autocomplete.action", 
  {method:"post",minlength:1,varname:"queryString",
  onSelect:function(data,json){
  id=json.id;
  return json.name;
  }
  });
});

$(document).ready(function() {
  $("#savesss").click(function() {
  document.location.href="save.action?id="+id
  });
});

</script>
</head>
<body>
<h1>第一个程序</h1>
<a href="">Link</a>
<hr />
<ol id="orderedlist">
<li>fsdg</li>
<li>sdfg</li>
<li>王朝</li>
</ol>
<hr />
<h1>相邻元素的选择</h1>
<h2>FAQ</h2>
<dl id="faq">
 <dt>为什么使用jQuery?</dt>
 <dd>jQuery可以用最少的javascript代码实现最多的功能,而且性能很好。</dd>
 <dt>和jQuery类似的api还有哪些?</dt>
 <dd>比如prototype、mootools、YUI、dojo和extjs等。</dd>
</dl>

<hr />
<label for="province">你来自哪个省/直辖市:</label><input id="province" type="text" />
<input id="savesss" type="button" />
</body>
</html>
 

 

 

action的配置

<struts>
 <constant name="struts.objectFactory"
  value="org.apache.struts2.spring.StrutsSpringObjectFactory" />

 <package name="/city" extends="json-default">
  <action name="autocomplete" class="autocompleteAction" method="query">
  <result type="json">
  <param name="root">results</param>
  </result>
  </action>

 </package>
</struts>
 

 

实体类

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值