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

📄 createtree.java

📁 一个信息发布系统 基于jsp+servlet+tomcat 用户分管理员跟普通用户 普通用户有发布信息 查询信息 修改信息 回复信息 管理员拥有普通用户的功能 此外还具有删除信息 管理信息的回复的功能
💻 JAVA
字号:
package control;
import java.io.PrintWriter;
import java.sql.*;
import control.*;
import model.*;
import java.util.*;
public class CreateTree 
{
	private PrintWriter out;

	public PrintWriter getOut() {
		return out;
	} 

	public void setOut(PrintWriter out) {
		this.out = out;
	}
	/**
	 * 构造PCName的子节点
	 * @param con
	 * @param PCName 父节点名称
	 */
	public void init(Connection con,String PCName,int laype)
	{
		CategoryCom com = new CategoryCom("jdbc:mysql://localhost/mybbs","root", "root123");
		Category category ;
		String sql = "select CCName,HasChild,CPath from relation where PCName='" + PCName + "'";
		String tempSQL = "";
		int total = 0;    //统计节点PCName 共有多少个下一阶节点
		
		String tempCCName = "";
		boolean tempHasChild = false;
		String  tempCPath = "";
		
		String space = "";
		for(int i = 0;i<laype;++i)
			space += "&nbsp;&nbsp;&nbsp;";   //缩进  根据laype层数来进行缩进
		try
		{
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery(sql);
			Statement tempST = con.createStatement();
			ResultSet tempRS;
			rs.last();
			total = rs.getRow();
			rs.beforeFirst();
			
			if(total != 0) //如果下一阶节点存在
			{
				while(rs.next())
				{
					tempCCName = rs.getString("CCName"); //得到该节点PCName的下一阶节点名称tempCCName
					tempCPath = rs.getString("CPath");
					category = com.getCategory(tempCCName);
					
					String children = null;
					String tempchildren = "";
					tempSQL = "select CCName,HasChild,CPath from relation where PCName='" + tempCCName + "'";//查找该节点tempCCName是否有下一阶节点
					tempRS = tempST.executeQuery(tempSQL);
					while(tempRS.next())
					{
						children = tempRS.getString("CCName");//得到下一阶节点的字符串列表   作为js方法(pfm_)的参数
						tempchildren += (children + ",");
					}
					tempRS.beforeFirst();
					
					if(children!=null)
					{
						int templaype = laype+1;
					    out.println("<tr id=" + tempCCName + " style=\"display:none;\">"	
					    	   +"<td style=\"width:10\"><input type=\"checkbox\" name=\"checkbox\" value="+category.getCName()+" /></td>"
							   +"<td> "+space+"<a href=\"javascript:pfm_('"+tempchildren.substring(0, tempchildren.length()-1)+"','" +tempCCName+"')\">"+"<img id=\"menu_img_"+tempCCName+"\" src=\"images/close.jpg\"/></a>"+category.getCName()+"</td>"
							  
							   +"<td>"+category.getCdetail()+"</td>"
							   +"<td>"+category.getCCreateDate() +"</td>"
							   +"<td>"+category.getCCount() +"</td>"
							   +"<td><a href=\"UpdateCategory.jsp?cname="+category.getCName() +"&detail="+category.getCdetail()+"\">编辑</a>"
							   +"<a href=\"DelCategory?cpath="+category.getCPath() +"&cname="+category.getCName() +"\" onclick=\"return a()\">删除</a></td>"
							   +"</tr>");                   //输出该节点到jsp页面
					    init(con,tempCCName,templaype);
					}
					
					else
						 out.println("<tr id=" + tempCCName + "  style=\"display:none;\">"
								 +"<td style=\"width:10\"><input type=\"checkbox\" name=\"checkbox\" value="+category.getCName()+" /></td>"
								   +"<td>"+space+"<img id=\"menu_img_229\" src=\"images/open.jpg\"/></a>"+category.getCName()+"</td>" 
								   +"<td>"+category.getCdetail()+"</td>"
								   +"<td>"+category.getCCreateDate() +"</td>"
								   +"<td>"+category.getCCount() +"</td>"
								   +"<td><a href=\"UpdateCategory.jsp?cname="+category.getCName() +"&detail="+category.getCdetail()+"\">编辑</a>"
								   +"<a href=\"DelCategory?cpath="+category.getCPath() +"&cname="+category.getCName() +"\" onclick=\"return a()\">删除</a></td>"
								   +"</tr>");
							
				}
			}
			
		}
		catch(SQLException e){}
	}
	
	
	public void init2(Connection con,String PCName,int laype)
	{
		CategoryCom com = new CategoryCom("jdbc:mysql://localhost/mybbs","root", "root123");
		Category category ;
		String sql = "select CCName,HasChild,CPath from relation where PCName='" + PCName + "'";
		String tempSQL = "";
		int total = 0;    //统计节点PCName 共有多少个下一阶节点
		
		String tempCCName = "";
		boolean tempHasChild = false;
		String  tempCPath = "";
		
		String space = "";
		for(int i = 0;i<laype;++i)
			space += "&nbsp;&nbsp;&nbsp;";   //缩进  根据laype层数来进行缩进
		try
		{
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery(sql);
			Statement tempST = con.createStatement();
			ResultSet tempRS;
			rs.last();
			total = rs.getRow();
			rs.beforeFirst();
			
			if(total != 0) //如果下一阶节点存在
			{
				while(rs.next())
				{
					tempCCName = rs.getString("CCName"); //得到该节点PCName的下一阶节点名称tempCCName
					tempCPath = rs.getString("CPath");
					category = com.getCategory(tempCCName);
					
					String children = null;
					String tempchildren = "";
					tempSQL = "select CCName,HasChild,CPath from relation where PCName='" + tempCCName + "'";//查找该节点tempCCName是否有下一阶节点
					tempRS = tempST.executeQuery(tempSQL);
					while(tempRS.next())
					{
						children = tempRS.getString("CCName");//得到下一阶节点的字符串列表   作为js方法(pfm_)的参数
						tempchildren += (children + ",");
					}
					tempRS.beforeFirst();
					
					if(children!=null)
					{
						int templaype = laype+1;
					    out.println("<tr id=" + tempCCName + " style=\"display:none;\">"							   
							   +"<td>"+space+"<a href=\"javascript:pfm_('"+tempchildren.substring(0, tempchildren.length()-1)+"','" +tempCCName+"')\">"+"<img id=\"menu_img_229\" src=\"images/close.jpg\"/></a>"
							   +"<a href = \"ShowAllCardList?cpath="+category.getCPath()+"&cname="+category.getCName()+"&pagecount=1&pagenum=1&command=show&sortcondition=byTime\">"+category.getCName()+"</a></td>"
							   +"<td>"+category.getCdetail()+"</td>"
							   +"<td>"+category.getCCreateDate() +"</td>"
							   +"<td>"+category.getCCount() +"</td>"				   
							   +"</tr>");                   //输出该节点到jsp页面
					    init2(con,tempCCName,templaype);
					}
					
					else
						 out.println("<tr id=" + tempCCName + "  style=\"display:none;\">"
								   +"<td>"+space+"<img id=\"menu_img_229\" src=\"images/open.jpg\"/></a>"
								   +"<a href = \"ShowAllCardList?cpath="+category.getCPath()+"&cname="+category.getCName()+"&pagecount=1&pagenum=1&command=show&sortcondition=byTime\">"+category.getCName()+"</a></td>"
								   +"<td>"+category.getCdetail()+"</td>"
								   +"<td>"+category.getCCreateDate() +"</td>"
								   +"<td>"+category.getCCount() +"</td>"
								   +"</tr>");
							
				}
			}
			
		}
		catch(SQLException e){}
	}
}

⌨️ 快捷键说明

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