Struts2+JQuery+JSON
1.Action [code="java"] package com.fayhong.action.basicdata; import java.util.List; import org.apache.struts2.ServletActionContext; import net.sf.json.JSONArray; import com.fayhong.model.Country; import com.fayhong.service.basicdata.BasicDataService; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; public class JsonAction extends ActionSupport{ private BasicDataService basicDataService; private String countryJSON; public String findCountryList() { StringBuffer sb = new StringBuffer(); String number = ServletActionContext.getRequest().getParameter("number"); List countryList = basicDataService.findCountry(null,number); if (countryList.size() > 0) { sb.append("{"); for (int i = 0; i < countryList.size(); i++) { Country country = (Country) countryList.get(i); sb.append(country.getCountryId()); sb.append(":"); sb.append("\""); sb.append(country.getCountryId()); sb.append("\""); if (i != (countryList.size() - 1)) sb.append(","); } sb.append("}"); } JSONArray array = new JSONArray().fromObject(countryList); countryJSON=array.toString(); // cityJSON = sb.toString();// 返回的数据 System.out.println(sb.toString()); System.out.println("cityJSON=="+countryJSON); return Action.SUCCESS; } public void setBasicDataService(BasicDataService basicDataService) { this.basicDataService = basicDataService; } public String getCountryJSON() { return countryJSON; } public void setCountryJSON(String countryJSON) { this.countryJSON = countryJSON; } }[/code] 2.xml [code="xml"] [/code] 3.jsp [code="html"] <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> test jQuery [/code]