JSP创建树时,引用dwr的步骤:
1、下载dwr的JS文件,放在WebRoot或其子目录下。
2、在web.xml中配置dwr
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
3、引用dwr.js。
<script type="text/javascript" src="js/dtree.js"></script>
<link rel="stylesheet" href="js/dtree.css" type="text/css">
<script type="text/javascript" src="dwr/engine.js"></script>------必须写
4、案例
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="java.util.*"
import="com.XXXX.interface/XXXX.js"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>导航栏</title>
<script type="text/javascript" src="js/dtree.js"></script>
<link rel="stylesheet" href="js/dtree.css" type="text/css">
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/interface/XXX.js"></script>
</head>
<body>
<p>
<a href="javascript:d.openAll();">全部展开</a>
<a href="javascript:d.closeAll();">全部关闭</a>
</p>
<p>
<script type="text/javascript">
//从js中定义一个dTree
var d = new dTree('d');
d.config.useCookies = false;
d.config.useStatusText = true;
d.config.closeSameLevel = true;
d.add(0,-1,"办公管理系统");//当前node:0,没有父节点,即pid:-1
//一级导航--树 当前node:1,pid:0
d.add(1,"XXX");
d.add(2,“XXX");
//二级导航
d.add(11,1,"XXXX");
d.add(12,"XXXX");
d.add(21,2,"XXXX");
d.add(22,"XXXX");
document.write(d);
</script>
</p>
</body>
</html>