问题描述
1.struts.xmlXml代码1.<packagename="ajax"namespace="/ajax"extends="json-default">2.<actionname="productCategoryAjaxAction"class="productCategoryAction">3.<resulttype="json">4.<paramname="root">jsonData</param>5.</result>6.</action>7.</package><packagename="ajax"namespace="/ajax"extends="json-default"><actionname="productCategoryAjaxAction"class="productCategoryAction"><resulttype="json"><paramname="root">jsonData</param></result></action></package>2.Java代码1.@Component("productCategoryAction")2.@Scope("prototype")3.publicclassproductCategoryActionextendsActionSupport{4.privateStringjsonData;5.6.publicStringgetJsonData(){7.returnjsonData;8.}9.10.publicvoidsetJsonData(StringjsonData){11.this.jsonData=jsonData;12.}13.14./**15.*取得某节下的所有字节点16.*17.*@returnString跳转标志18.*/19.publicStringgenerateTree(){20.//下面这段是照着jstree1.0的json例子加进来的,只加了“”转义符号。21.privateStringBuffertreeTemp=newStringBuffer();22.treeTemp.append("[{");23.treeTemp.append(""data":"Anode",");24.treeTemp.append(""children":["Child1","Child2"]},");25.treeTemp.append("{"attr":{"id":"li.node.id"},");26.treeTemp.append(""data":{"title":"Longformatdemo","attr":{"href":"#"}}}]");27.jsonData=treeTemp.toString();28.returnSUCCESS;29.}30.}@Component("productCategoryAction")@Scope("prototype")publicclassproductCategoryActionextendsActionSupport{privateStringjsonData;publicStringgetJsonData(){returnjsonData;}publicvoidsetJsonData(StringjsonData){this.jsonData=jsonData;}/***取得某节下的所有字节点**@returnString跳转标志*/publicStringgenerateTree(){//下面这段是照着jstree1.0的json例子加进来的,只加了“”转义符号。privateStringBuffertreeTemp=newStringBuffer();treeTemp.append("[{");treeTemp.append(""data":"Anode",");treeTemp.append(""children":["Child1","Child2"]},");treeTemp.append("{"attr":{"id":"li.node.id"},");treeTemp.append(""data":{"title":"Longformatdemo","attr":{"href":"#"}}}]");jsonData=treeTemp.toString();returnSUCCESS;}}3.JSP页面:Html代码1.<%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>2.<%@includefile="/pages/common/TagLibs.jsp"%>3.<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">4.<html>5.<head>6.<title></title>7.<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">8.<scriptsrc="<common:webRoot/>/js/jstree/jquery.js"></script>9.10.<scriptsrc="<common:webRoot/>/js/jstree/jquery.cookie.js"></script>11.<scriptsrc="<common:webRoot/>/js/jstree/jquery.hotkeys.js"></script>12.<scriptsrc="<common:webRoot/>/js/jquery.jstree.js"></script>13.14.<linkrel="stylesheet"href="<common:webRoot/>/css/jstree/docs/syntax/!style.css">15.<linkrel="stylesheet"href="<common:webRoot/>/css/jstree/docs/!style.css">16.17.<scriptsrc="<common:webRoot/>/js/jstree/docs/syntax/!script.js"></script>18.</head>19.<body>20.<divid="tree1"></div>21.22.<scripttype="text/javascript">23.$(function(){24.$.jstree._themes="<common:webRoot/>/jstreethemes/";25.$("#tree1").jstree({26."json_data":{27."ajax":{28."url":"<common:webRoot/>/ajax/productCategoryAjaxAction!generateTree.action"29.}30.},31."plugins":["themes","json_data"]32.});33.});34.</script>35.36.</body>37.</html><%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><%@includefile="/pages/common/TagLibs.jsp"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title></title><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"><scriptsrc="<common:webRoot/>/js/jstree/jquery.js"></script><scriptsrc="<common:webRoot/>/js/jstree/jquery.cookie.js"></script><scriptsrc="<common:webRoot/>/js/jstree/jquery.hotkeys.js"></script><scriptsrc="<common:webRoot/>/js/jquery.jstree.js"></script><linkrel="stylesheet"href="<common:webRoot/>/css/jstree/docs/syntax/!style.css"><linkrel="stylesheet"href="<common:webRoot/>/css/jstree/docs/!style.css"><scriptsrc="<common:webRoot/>/js/jstree/docs/syntax/!script.js"></script></head><body><divid="tree1"></div><scripttype="text/javascript">$(function(){$.jstree._themes="<common:webRoot/>/jstreethemes/";$("#tree1").jstree({"json_data":{"ajax":{"url":"<common:webRoot/>/ajax/productCategoryAjaxAction!generateTree.action"}},"plugins":["themes","json_data"]});});</script></body></html>在Firefox看到的返回数据:响应:Java代码1."[{"data":"Anode","children":["Child1","Child2"]},{"attr":{"id":"li.node.id"},"data":{"title":"Longformatdemo","attr":{"href":"#"}}}]""[{"data":"Anode","children":["Child1","Child2"]},{"attr":{"id":"li.node.id"},"data":{"title":"Longformatdemo","attr":{"href":"#"}}}]"jstree1.0的json例子:Java代码1.[2.{3."data":"Anode",4."children":["Child1","Child2"]5.},6.{7."attr":{"id":"li.node.id"},8."data":{9."title":"Longformatdemo",10."attr":{"href":"#"}11.}12.}13.][{"data":"Anode","children":["Child1","Child2"]},{"attr":{"id":"li.node.id"},"data":{"title":"Longformatdemo","attr":{"href":"#"}}}]页面没有报错,也没有任务内容,是不是JSON格式不对?请指教,不胜感激。
解决方案
解决方案二:
该回复于2011-01-18 17:03:14被版主删除
解决方案三:
高手都在数年终奖呢!