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

📄 treeaction.java

📁 js 异步加载 tree 采用ajax技术
💻 JAVA
字号:
package yuwu.cn.com.action;

import java.util.List;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import yuwu.cn.com.dao.TreeDAO;
import yuwu.cn.com.vo.LineVO;
import yuwu.cn.com.vo.StationVO;
import yuwu.cn.com.vo.Transformer;

public class TreeAction extends DispatchAction {
	/**
	 * 查询出所有变电站
	 */
	public ActionForward tree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			response.setHeader("Cache-Control", "no-store");
			response.setHeader("Pragma", "No-cache");
			response.setDateHeader("Expires", 0);
			response.setContentType("text/xml; charset=GBK");
			java.io.PrintWriter pout = response.getWriter();
			StringBuffer buf = new StringBuffer();
			
			TreeDAO dao = new TreeDAO();
			//查询出所有的变电站
			List<StationVO> list = dao.getStation();
			// 树节点的名字
			String treeId = null;
			for (StationVO e : list) {
				treeId = "var item_" + e.getStationId();
				buf.append(treeId + "=new WebFXLoadTreeItem('");
				buf.append(e.getStationName());
				buf.append("','accessTreeAction.do?method=subTree&psoId=");
				buf.append(e.getStationId());
				buf.append("&function=showPso', 'javascript:showPso(");
				buf.append(e.getStationId());
				buf.append(")');");
				buf.append("item_root.add(item_" + e.getStationId() + ");");
			}
			System.out.println(buf.toString());
			//上面for循环中的append()方法,仅仅是为了拼一条如下的字符串
			buf.append("var item_3140 = new WebFXLoadTreeItem('GUEI','accessTreeAction.do?method=subTree&psoId=3140&function=showPso', 'javascript:showPso(3140)');");
			buf.append("item_root.add(item_3140);");
			System.out.println(buf.toString());
			pout.println(buf.toString());
			pout.flush();
			pout.close();
		} catch (java.lang.Exception k) {
			k.printStackTrace();
		}

		return null;
	}
	
	/**
	 *查询指定变电站下面的线路
	 * 
	 */
	public ActionForward subTree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			StringBuffer buf = new StringBuffer();
       
			String stationId = request.getParameter("psoId");
			long id = Integer.parseInt(stationId);
            System.out.println("变电站ID为:" + stationId);
            
            TreeDAO dao = new TreeDAO();
            //查询出指定电站下的线路
            List<LineVO> list = dao.getLine(id);
			String treeId = null;
			buf.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
			buf.append("<tree>");
			for (LineVO e : list) {
				treeId = "var itemsubtree_" + e.getLindId();
				buf.append("<tree text=\"");
				buf.append(e.getLineName());
				buf.append("\" src=\"accessTreeAction.do?method=subsubTree&amp;lineId=");
				buf.append(e.getLindId());
				buf.append("\" action=\"javascript:showPso(");
				buf.append(e.getLindId());
				buf.append(")\"/>");
			}
//上面for循环中的append()方法,仅仅是为了拼一条如下的字符串,
//唯一的不同的是从数据库中读者“text=\"线路一\"”的线路名字  4240相当于线路ID,上面是从数据库获取
// buff.append("<tree text=\"线路一\" src=\"accessTreeAction.do?method=subsubTree&amp;lineId=4240\" action=\"javascript:showPso(4240)\"/>");
//			buff.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
//			buff.append("<tree>");
//			buf.append("<tree text=\"茶恩302\" action=\"javascript:showPso(4240)\">");
//			buf.append("<tree text=\"变压器a\" action=\"javascript:showPso(5327)\"/>");
//			buf.append("<tree text=\"变压器b\" action=\"javascript:showPso(5327)\"/>");
//			buf.append("</tree>");
			buf.append("</tree>");

			System.out.println(buf.toString());

			response.setHeader("Cache-Control", "no-store");
			response.setHeader("Pragma", "No-cache");
			response.setDateHeader("Expires", 0);
			response.setContentType("text/xml; charset=GBK");
			java.io.PrintWriter pout = response.getWriter();
			pout.println(buf.toString());
			pout.flush();
			pout.close();
		} catch (java.lang.Exception k) {
			k.printStackTrace();
		}
        return null;
	}
	
	/**
	 *查询指定线路下面的变压器 
	 */
	public ActionForward subsubTree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			StringBuffer buff = new StringBuffer();
            
			String stationId = request.getParameter("lineId");
			long id = Integer.parseInt(stationId);
            System.out.println("变电站ID为:" + stationId);
            
            TreeDAO dao = new TreeDAO();
            List<Transformer> list = dao.getTransformer(id);   
            buff.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
			buff.append("<tree>");
			for(int i = 0;i < list.size(); i++){
					Transformer tran = new Transformer();
					tran = list.get(i);
					buff.append("<tree text=\"");
					buff.append(tran.getName());
					buff.append("\" action=\"javascript:showPso(");
					buff.append(tran.getCommId());
					buff.append(")\"/>");
			}
            
//			buff.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
//			buff.append("<tree>");
//上面for循环中的append()方法,仅仅是为了拼一条如下的字符串,
//			buff.append("<tree text=\"茶恩302\" action=\"javascript:showPso(4240)\">");
//			buff.append("<tree text=\"变压器a\" action=\"javascript:showPso(5327)\"/>");
//			buff.append("<tree text=\"变压器b\" action=\"javascript:showPso(5327)\"/>");
//			buff.append("</tree>");
			buff.append("</tree>");

			System.out.println(buff.toString());

			response.setHeader("Cache-Control", "no-store");
			response.setHeader("Pragma", "No-cache");
			response.setDateHeader("Expires", 0);
			response.setContentType("text/xml; charset=GBK");
			java.io.PrintWriter pout = response.getWriter();
			pout.println(buff.toString());
			pout.flush();
			pout.close();
		} catch (java.lang.Exception k) {
			k.printStackTrace();
		}

		return null;
	}
	
}

⌨️ 快捷键说明

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