xloadTree和struts实现目录树动态加载
页面:testTree.jsp 需要导入xtree.js,xmlextras.js,xloadtree.js,xtree.css
可以在这里下载
http://webfx.eae.net/dhtml/xloadtree/xloadtree.html
<%@ page language="java"%><%@ page contentType="Text/html;charset=UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>My JSP 'testTree.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><script type="text/javascript" src="/view/test/xtree.js"></script> <script type="text/javascript" src="/view/test/xmlextras.js"></script> <script type="text/javascript" src="/view/test/xloadtree.js"></script> <link type="text/css" rel="stylesheet" href="/view/test/xtree.css" /> </head> <body> This is my JSP page. <br> <script type="text/javascript">/// XP LookwebFXTreeConfig.rootIcon = "/view/test/images/xp/folder.png";webFXTreeConfig.openRootIcon = "/view/test/images/xp/folder.png";webFXTreeConfig.folderIcon = "/view/test/images/xp/folder.png";webFXTreeConfig.openFolderIcon = "/view/test/images/xp/openfolder.png";webFXTreeConfig.fileIcon = "/view/test/images/xp/file.png";webFXTreeConfig.lMinusIcon = "/view/test/images/xp/Lminus.png";webFXTreeConfig.lPlusIcon = "/view/test/images/xp/Lplus.png";webFXTreeConfig.tMinusIcon = "/view/test/images/xp/Tminus.png";webFXTreeConfig.tPlusIcon = "/view/test/images/xp/Tplus.png";webFXTreeConfig.iIcon = "/view/test/images/xp/I.png";webFXTreeConfig.lIcon = "/view/test/images/xp/L.png";webFXTreeConfig.tIcon = "/view/test/images/xp/T.png";//这里最好写绝对路径var tree = new WebFXTree("智能化多媒体培训平台");tree.add(new WebFXTreeItem("Tree me 1"));tree.add(new WebFXLoadTreeItem("Tree me 2","/view/test/test1.xml"));//这里也可以是xml路径tree.add(new WebFXTreeItem("Tree me 3"));tree.add(new WebFXLoadTreeItem("Tree me 4","/testTree.do"));//这里也可以是Action请求document.write(tree);</script> </body></html>
package testTree;import java.io.PrintWriter;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;public class TestTreeAction extends Action{@Overridepublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {String asdf = request.getParameter("id");System.out.println(asdf); response.setCharacterEncoding("gb2312"); response.setContentType("text/xml charset=gb2312"); PrintWriter out = response.getWriter(); out.write("<?xml version="1.0" encoding="gb2312"?>"); out.write("<tree>"); int asdfInt = 0; if(asdf == null || asdf.equals("") || asdf.equals("0")){ for(int i=1; i<=100; i++) { out.write("<tree text="+"""+"目录-"+i+"""+" src="/testTree.do?id="+i+"" />"); } }else{ asdfInt = Integer.valueOf(asdf); if(asdfInt>= 1 || asdfInt <=100) { for(int i=1; i<=100; i++) { if(asdfInt == i) { for(int k=101; k<=200; k++) { out.write("<tree text="+"""+"目录-"+i+"--"+k+"""+" src="/testTree.do?id="+i+k+"" />"); } } } } if(asdfInt>= 1101 || asdfInt <=100200) { for(int i=1101; i<=100200; i++) { if(asdfInt == i) { for(int k=1; k<=100; k++) { out.write("<tree text="看课件啦"+i+"--"+k+"" action="http://192.168.1.109:8080/Gw_studytrainunitSI_retrieve.do?trainunit_id=679" />"); //out.write("<tree text="习题导入" action="/view/jsp/share/excel/exerciseImport.jsp" target="mainFrame" />"); } } } } } out.write("</tree>"); out.flush();return null;}}