求JAVA AJAX 动态树 示例代码

纵道软件 2008-08-05 04:12:07
求JAVA AJAX 动态树 示例代码,
从数据里读取树结构出来加载到页面,点击父节点才加载子节点,
哪位高手指教下,发个示例过来看看.最好是MyEclipse工程的,191436743@qq.com,QQ:191436743,谢谢.


--------------------------------------------------------------------
以下内容为自动编辑的内容,并非楼主的发贴内容,此仅用于显示而已,并无任何其他特殊作用
楼主【skybehind】截止到2008-08-05 16:12:15的历史汇总数据(不包括此帖):
发帖的总数量:1 发帖的总分数:20 每贴平均分数:20
回帖的总数量:1 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:20
结贴的百分比:0.00 % 结分的百分比:0.00 %
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html

取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=skybehind
...全文
185 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanson1232992 2010-09-30
  • 打赏
  • 举报
回复
梅花雪的是动态树吗,听说市一次加载的哦?
fengyezaihong 2008-08-07
  • 打赏
  • 举报
回复
用jquery的插件吧!
kokobox 2008-08-07
  • 打赏
  • 举报
回复
lz可以去下个梅花雪的动态树,里面就有示例和源码,而且都比较详细

mike1980 2008-08-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 kokobox 的回复:]
lz可以去下个梅花雪的动态树,里面就有示例和源码,而且都比较详细
[/Quote]
我也用过,不错。
恶魔在人间 2008-08-07
  • 打赏
  • 举报
回复

<%@ page language="java" %>
<%@ page import="com.xpd.www.pojo.*" %>
<%@ page import="com.xpd.www.util.*" %>
<%@ page import="com.xpd.www.service.*" %>
<html>
<head>

<title>dynamic tree view</title>
<link rel="stylesheet" href = "css/tree.css">
<script type="text/javascript">

function sack(file){
this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
this.requestFile = file;
this.method = "POST";
this.URLString = "";
this.encodeURIString = true;
this.execute = false;

this.onLoading = function() { };
this.onLoaded = function() { };
this.onInteractive = function() { };
this.onCompletion = function() { };

this.createAJAX = function() {
try {
this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (err) {
this.xmlhttp = null;
}
}
if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
this.xmlhttp = new XMLHttpRequest();
if (!this.xmlhttp){
this.failed = true;
}
};

this.setVar = function(name, value){
if (this.URLString.length < 3){
this.URLString = name + "=" + value;
} else {
this.URLString += "&" + name + "=" + value;
}
}

this.encVar = function(name, value){
var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
return varString;
}

this.encodeURLString = function(string){
varArray = string.split('&');
for (i = 0; i < varArray.length; i++){
urlVars = varArray[i].split('=');
if (urlVars[0].indexOf('amp;') != -1){
urlVars[0] = urlVars[0].substring(4);
}
varArray[i] = this.encVar(urlVars[0],urlVars[1]);
}
return varArray.join('&');
}

this.runResponse = function(){
eval(this.response);
}

this.runAJAX = function(urlstring){
this.responseStatus = new Array(2);
if(this.failed && this.AjaxFailedAlert){
alert(this.AjaxFailedAlert);
} else {
if (urlstring){
if (this.URLString.length){
this.URLString = this.URLString + "&" + urlstring;
} else {
this.URLString = urlstring;
}
}
if (this.encodeURIString){
var timeval = new Date().getTime();
this.URLString = this.encodeURLString(this.URLString);
this.setVar("rndval", timeval);
}
if (this.element) { this.elementObj = document.getElementById(this.element); }
if (this.xmlhttp) {
var self = this;
if (this.method == "GET") {
var totalurlstring = this.requestFile + "?" + this.URLString;
this.xmlhttp.open(this.method, totalurlstring, true);
} else {
this.xmlhttp.open(this.method, this.requestFile, true);
}
if (this.method == "POST"){
try {
this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
} catch (e) {}
}

this.xmlhttp.send(this.URLString);
this.xmlhttp.onreadystatechange = function() {
switch (self.xmlhttp.readyState){
case 1:
self.onLoading();
break;
case 2:
self.onLoaded();
break;
case 3:
self.onInteractive();
break;
case 4:
self.response = self.xmlhttp.responseText;
self.responseXML = self.xmlhttp.responseXML;
self.responseStatus[0] = self.xmlhttp.status;
self.responseStatus[1] = self.xmlhttp.statusText;
self.onCompletion();
if(self.execute){ self.runResponse(); }
if (self.elementObj) {
var elemNodeName = self.elementObj.nodeName;
elemNodeName.toLowerCase();
if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
self.elementObj.value = self.response;
} else {
self.elementObj.innerHTML = self.response;
}
}
self.URLString = "";
break;
}
};
}
}
};
this.createAJAX();
}
</script>
<script type="text/javascript">
function showHide( id )
{
var el= document.getElementById( id );
var bExpand = true;
var images = el.getElementsByTagName("IMG");
if (images[0].src.indexOf("minus.gif")!=-1)
{
bExpand = false;
images[0].src="images/plus.gif";
}else{
images[0].src="images/minus.gif";
}
var subs=el.lastChild;
if(bExpand)
subs.style.display="block";
else
subs.style.display="none";
}

function getSubTree( id )
{
var submitURL="treeview?parent="+id;
postXmlHttp( submitURL, 'parseSubTree("'+id+'")' ,'load("'+id+'")');
}
function parseSubTree(id)
{

var el= document.getElementById( id );
var ulElmt= document.createElement("UL");
ulElmt.innerHTML=_xmlHttpRequestObj.responseText;
el.appendChild(ulElmt);
var images = el.getElementsByTagName("IMG");
images[0].setAttribute("src", "images/minus.gif");
images[0].setAttribute("onclick", "showHide('"+id+"')");
var aTag = el.getElementsByTagName("A");
aTag[0].setAttribute("onclick", "showHide('"+id+"')");
var loadDiv= document.getElementById( "load" );
loadDiv.style.display="none";
}
function load(id)
{
var loadDiv= document.getElementById( "load" );
loadDiv.style.display="block";
}
var _postXmlHttpProcessPostChangeCallBack;
var _xmlHttpRequestObj;
var _loadingFunction;


function postXmlHttp( submitUrl, callbackFunc ,loadFunc)
{
_postXmlHttpProcessPostChangeCallBack = callbackFunc;
_loadingFunction = loadFunc;
if(window.XMLHttpRequest)
{
_xmlHttpRequestObj=new XMLHttpRequest();
_xmlHttpRequestObj.open('POST',submitUrl,true);
_xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
_xmlHttpRequestObj.send("");
}
else if(window.ActiveXObject)
{
_xmlHttpRequestObj=new ActiveXObject("Microsoft.XMLHTTP");
_xmlHttpRequestObj.open('POST',submitUrl,true);
_xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
_xmlHttpRequestObj.send();
}
};

function postXmlHttpProcessPostChange( )
{
if( _xmlHttpRequestObj.readyState==4 && _xmlHttpRequestObj.status==200 )
{
setTimeout( _postXmlHttpProcessPostChangeCallBack, 2 );
}
if ( _xmlHttpRequestObj.readyState==1 )
{
setTimeout( _loadingFunction, 2 );
}
}
</script>

</head>
<body>
<div id="load" style="display:none"> <img src="images/loading.gif">Loading data..</div>
<ul class="tree">
<%
Category topCate = new Category(0);
TreeviewElement[] top = topCate.getChildren();
for(int i= 0;i<top.length;i++)
out.println(treeviewRender.renderTreeViewAjax(top[i],false));
%>
</ul>
</body>
</html>

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xpd.www.pojo.Category;
import com.xpd.www.service.TreeviewElement;
import com.xpd.www.util.treeviewRender;

public class TreeviewServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
String parentID = request.getParameter("parent");//获得id的值
if (parentID!=null&&!parentID.equals(""))//如果不为null和空
{
Category category = new Category(Integer.parseInt(parentID));//创建Category对象
TreeviewElement[] top = category.getChildren();//得到该分类的所有下级分类
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
for(int i= 0;i<top.length;i++)//循环显示每个分类
out.println(treeviewRender.renderTreeViewAjax(top[i],false));
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {

doPost(request, response);
}

}
大河V5 2008-08-06
  • 打赏
  • 举报
回复
上google去baidu之

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧