package com.webjet.web.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.opensymphony.xwork2.ActionSupport;
import com.webjet.bean.China;
import com.webjet.service.ChinaService;
@Controller
@Scope("prototype")
public class Jchina extends ActionSupport {
private static final long serialVersionUID = 1L;
@Autowired
private ChinaService chinaservice;
public ChinaService getChinaservice() {
return chinaservice;
}
public void setChinaservice(ChinaService chinaservice) {
this.chinaservice = chinaservice;
}
private List<China> chinaList;
public String execute() throws Exception{
setChinaList(chinaservice.show());
JSONArray jsonArray2 = JSONArray.fromObject(chinaList);
//把java数组转化成转化成json对象
ServletActionContext.getResponse().getWriter().print(new String(jsonArray2.toString().getBytes(),"iso8859-1"));
return null;
}
public List<China> getChinaList() {
return chinaList;
}
public void setChinaList(List<China> chinaList) {
this.chinaList = chinaList;
}
}
------------------------------------------------------------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<HTML>
<HEAD>
<TITLE> ZTREE DEMO - Standard Data </TITLE>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/demo.css" type="text/css">
<link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery.ztree.core-3.5.js"></script>
<SCRIPT type="text/javascript">
<!--
var setting = {
data: {
simpleData: {
enable: true
}
}
};
//var zNodes =$(function(){ var jsonArray = $.load("chinaList")});
$(document).ready(function(){
var zNodes;
jQuery.getJSON(
"jchina.action",function(object){
zNodes = object;
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
});
});
//-->
</SCRIPT>
</HEAD>
<BODY>
<ul id="treeDemo" class="ztree"></ul>
</BODY>
</HTML>
--------------------------------------------------------------------------------------
function(object)里的object是jchina.action的输出值 ,另外znodes= jQuery.getJSON(
"jchina.action",function(object) 这样写是错误的