⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree_show.jsp

📁 用JAVA实现的对动态树状信息的管理。操作员可以通过IE浏览器查看整个树形结构信息
💻 JSP
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="com.socialite.bizlogic.util.CookieTool,
                 com.socialite.bizlogic.util.Char,
                 com.socialite.bizlogic.client.BizLogicClient,
                 com.socialite.bizlogic.util.XMLObject,
				 com.socialite.bizlogic.tree.TreeNodeObject,
				 com.socialite.bizlogic.tree.TreeObject,
				 com.socialite.bizlogic.tree.TreeIterator,
				 javax.swing.tree.DefaultTreeModel,
				 javax.swing.tree.DefaultMutableTreeNode"%>
<%!
   //把树结构组装成xml,以便用javascript显示
   public void xmlTreeGet(TreeIterator it,StringBuffer treeXML){
 
		TreeNodeObject node=null;
		DefaultMutableTreeNode dfNode=null;
		
		//遍历树,组装xml
		//首先是根节点
		if(it.hasNext()){
			dfNode=(DefaultMutableTreeNode)it.nextNode();
			node=(TreeNodeObject)dfNode.getUserObject();
			String name=node.getName();
			String url=node.getUrl();
			boolean isOpen=false;
			if(dfNode.isRoot()){
				isOpen=true;
			}
			
			if(dfNode.isLeaf()){//是叶子节点
				treeXML.append("<DSTree text=\"" + name + "\" href=\""+url+"\" target=\"box\" treeId=\""+node_id+"\" />");
				xml.append(Char.LINE_SEPARATOR);
		    }else if(isOpen){//是根节点
					treeXML.append("<DSTreeRoot text=\"" + name + "\" open=\"true\" href=\""+url+"\" target=\"box\" treeId=\""+node_id+"\" />");
			}else{//非叶子节点或根节点
				treeXML.append("<DSTree text=\"" + name + "\" open=\"false\" href=\""+url+"\" target=\"box\" treeId=\""+node_id+"\" />");
				
				//第归调用,继续组装xml
				xmlTreeGet(it,treeXML);
				
				treeXML.append("</DSTree>");
			}
		}
		treeXML.append("</DSTreeRoot>");
		//return treeXML.toString();
	
	}
	
%>


<%
    // 如果操作员没有登录,则转到登录页面
    String op_id = com.socialite.bizlogic.util.CookieTool.getCookieValue(request.getCookies(),"op_id");
    if(op_id==null)
    {
        response.sendRedirect("/login/logout.jsp");
        return;
    }  else if (op_id.equalsIgnoreCase("-1") ){
        response.sendRedirect("/login/logout.jsp");
        return;
    }
	request.setCharacterEncoding("gb2312");//处理中文显示问题
	
	TreeObject tObject=null;
	tObject=(TreeObject)application.getAttribute("tree");
	
	if(tObject!=null){//application对象中已经保存树对象
		
	}else{//application还没有保存树对象
		//向bizlogic请求整棵树树信息
		StringBuffer xml=new StringBuffer("<bizlogic><logic_name>com.socialite.bizlogic.businesslogic.treemanagementlogic.TreeManagementBusinessLogic</logic_name>");
    	xml.append(Char.LINE_SEPARATOR);
		xml.append("<requesttype>SHOW_TREE</requesttype>");
    	xml.append(Char.LINE_SEPARATOR);
    	xml.append("<requestparameter>");
    	xml.append("</requestparameter>");
    	xml.append(Char.LINE_SEPARATOR);
    	xml.append("</bizlogic>");
    	xml.append(Char.LINE_SEPARATOR);

    	BizLogicClient hc=new BizLogicClient();
    	String xmlResult=hc.send(xml.toString());

    	XMLObject xmlObj = new XMLObject(xmlResult,0);
		String result=xmlObj.getValue("bizlogic.resultcode");
		
		if("0".equals(result)){
		    //构造TreeObject对象
			tObject=new TreeObject(xmlObj);
			
			//将tObject保存到application
			application.setAttribute("tree",tObject);
			
	    }else{
			return;
	    }
	}
	
	DefaultTreeModel dtm=tObject.dfModel;
	TreeIterator it=new TreeIterator(dtm);//得到树的迭代器
	StringBuffer treeXML=new StringBuffer("");
	
	xmlTreeGet(it,treeXML);//用xml表示的树型结构,用于显示
	String xml=treeXML.toString();
%>

	
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>动态树型结构管理</title>
<script language="javascript" >
	//code by star time
	var HC = "color:#990000;border:1px solid #cccccc";
	var SC = "background-color:#efefef;border:1px solid #cccccc;color:#000000;";
	var IO = null;
function initTree(){
	var rootn = document.all.menuXML.documentElement;
	var sd = 0;
	document.onselectstart = function(){return false;}
	document.all.treeBox.appendChild(createTree(rootn,sd));
}
function createTree(thisn,sd){
	var nodeObj = document.createElement("span");
	var upobj = document.createElement("span");
	with(upobj){
		style.marginLeft = sd*10;
		className = thisn.hasChildNodes()?"hasItems":"Items";
		innerHTML = "<img src=open.gif class=ec>" + thisn.getAttribute("text") +"";
		
		onmousedown = function(){
			if(event.button != 1) return;
			if(this.getAttribute("cn")){
				this.setAttribute("open",!this.getAttribute("open"));
				this.cn.style.display = this.getAttribute("open")?"inline":"none";
				this.all.tags("img")[0].src = this.getAttribute("open")?"open.gif":"contract.gif";
			}
			if(IO){
				IO.runtimeStyle.cssText = "";
				IO.setAttribute("selected",false);
			}
			IO = this;
			this.setAttribute("selected",true);
			this.runtimeStyle.cssText = SC;
		}
		onmouseover = function(){
			if(this.getAttribute("selected"))return;
			this.runtimeStyle.cssText = HC;
		}
		onmouseout = function(){
			if(this.getAttribute("selected"))return;
			this.runtimeStyle.cssText = "";
		}
		oncontextmenu = contextMenuHandle;
		onclick = clickHandle;
	}

	if(thisn.getAttribute("treeId") != null){
		upobj.setAttribute("treeId",thisn.getAttribute("treeId"));
	}
	if(thisn.getAttribute("href") != null){
		upobj.setAttribute("href",thisn.getAttribute("href"));
	}
	if(thisn.getAttribute("target") != null){
		upobj.setAttribute("target",thisn.getAttribute("target"));
	}

	nodeObj.appendChild(upobj);
	nodeObj.insertAdjacentHTML("beforeEnd","<br>")

	if(thisn.hasChildNodes()){
		var i;
		var nodes = thisn.childNodes;
		var cn = document.createElement("span");
		upobj.setAttribute("cn",cn);
		if(thisn.getAttribute("open") != null){
			upobj.setAttribute("open",(thisn.getAttribute("open")=="true"));
			upobj.getAttribute("cn").style.display = upobj.getAttribute("open")?"inline":"none";
			if( !upobj.getAttribute("open"))upobj.all.tags("img")[0].src ="contract.gif";
		}
		
		for(i=0;i<nodes.length;cn.appendChild(createTree(nodes[i++],sd+1)));
		nodeObj.appendChild(cn);
	}
	else{
		upobj.all.tags("img")[0].src ="endnode.gif";
	}
	return nodeObj;
 }
window.onload = initTree;
</script>

<script language="javascript">
function clickHandle(){
	
}
function contextMenuHandle()
{
	event.returnValue = false;
	var treeId = this.getAttribute("treeId");

}
</script>
</head>

<body>
<xml id=menuXML>
<?xml version="1.0" encoding="GB2312"?>
<%
		out.println(xml);

%>
</xml>
<table width="803" height="375" border="0.2">
  <tr>
    <td height="33">&nbsp;</td>
  </tr>
  <tr>
        <td id=treeBox  valign=top>&nbsp;</td>
   </tr>
   <%
   //得到被选中的节点的信息
   
   %>
  <tr> 
      <td colspan="8" background="images/bg_table2.gif" height="7"></td>
  </tr>
  <tr>
    <td height="35"><div align="center">添加子节点&nbsp;&nbsp; 修改节点&nbsp;&nbsp; 删除节点</div></td>
  </tr>
</table>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -