Ext+Dwr动态树(增删改)

前端之家收集整理的这篇文章主要介绍了Ext+Dwr动态树(增删改)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Ext+Dwr动态树(增删改)

分类j2ee相关 398人阅读 评论(0) 收藏 举报

效果展示:

1.增加节点

2.删除节点

3.修改节点

技术分析:

利用DWR可以在客户端利用JavaScript直接调用服务端的Java方法并返回值给JavaScript就好像直接本地客户端调用一样DWR(根据Java类来动态生成JavaScrip代码).

树是一个我们日常用的组件,EXT给我们提供了一个非常好用的树控件,对于传统HTML页面完全靠手编写代码是非常困难的,因为要编写许多JS代码,还要实现AJAX功能,使用EXT编写树我们的工作将简单方便许多.

Ext.ux.DWRTreeLoader 是对树加载器 Ext.tree.TreeLoader 的扩展,实现了通过DWR直接调用后台JAVA类方法,将树结点返回到前台,除此之外,还支持对树进行查找时,将查找参数直接传给后台JAVA类方法.

具体JS代码实现:

[javascript] view plain copy
  1. //全局路径
  2. varbasePath="http://localhost:8080/exttree";
  3. if(typeof(glbRootPath)!="undefined"){
  4. basePath=glbRootPath;
  5. }
  6. //扩展窗体
  7. FormEditWin=function(){
  8. varcurFormWin;
  9. return{
  10. width:600,
  11. height:400,
  12. showAddDirWin:function(parentNode){
  13. //显示添加子目录窗口
  14. varnumber=parentNode.indexOf(parentNode.lastChild)+1;
  15. vareditpage=basePath
  16. +"/navigateedit?parentId="
  17. +parentNode.id+"&leaf=0&number="+number;
  18. varwindow=this.createWin("windirnew","新建目录节点",editpage,function(){
  19. parentNode.reload();
  20. });
  21. window.show();
  22. },108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> showAddLeafWin:function(parentNode){
  23. //显示添加子叶子节点窗口
  24. varnumber=parentNode.indexOf(parentNode.lastChild)+1;
  25. vareditpage=basePath
  26. +"/navigateedit?parentId="
  27. +parentNode.id+"&leaf=1&number="+number;
  28. this.createWin("winleafnew","新建叶子节点",248); line-height:18px"> parentNode.reload();
  29. });
  30. window.show();
  31. },248); line-height:18px"> showEditDirWin:function(node){
  32. //显示目录编辑窗口
  33. +"/navigateedit?id="+node.id;
  34. this.createWin("win"+node.id,node.text,153); background-color:inherit; font-weight:bold">varnodeparent=node.parentNode;
  35. vartree=node.getOwnerTree();
  36. nodeparent.on("expand",153); background-color:inherit; font-weight:bold">function(pnode){
  37. tree.getNodeById(node.id).select();
  38. this,{
  39. single:true
  40. node.parentNode.reload();
  41. showEditLeafWin://显示叶子节点编辑窗口
  42. createWin:function(winId,winTitle,iframePage,closeFun){
  43. //供各类型窗口创建时调用
  44. varwin=Ext.getCmp(winId);
  45. if(!win){
  46. win=newExt.Window({
  47. id:winId,248); line-height:18px"> title:"菜单编辑窗口-"+winTitle,
  48. width:this.width,
  49. height:this.height,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> maximizable:true,248); line-height:18px"> modal: html:"<iframewidth='100%'height='100%'frameborder='0'src='"
  50. +iframePage+"'></iframe>"
  51. this.reloadNavNode=closeFun;
  52. curFormWin=win;
  53. returnwin;
  54. reloadNavNode: close:if(curFormWin){
  55. curFormWin.close();
  56. }
  57. }();
  58. //导航树
  59. NavTree=varnav;
  60. varnavEditor;
  61. varleafMenu;
  62. vardirMenu;
  63. varloader;
  64. varroot;
  65. varremoveFlag=false;
  66. vartitleChangeFlag=false;
  67. varnodeSelected;
  68. varmgr;
  69. init:if(!mgr){
  70. Ext.Msg.alert("警告提示","请先通过NavTree.setMgr()设置mgr");
  71. return;
  72. if(!loader){
  73. loader=newExt.tree.TreeLoader({
  74. url:basePath+'/navigatejson'
  75. loader.on('beforeload',153); background-color:inherit; font-weight:bold">function(treeloader,node){
  76. treeloader.baseParams={
  77. id:node.id,248); line-height:18px"> method:'tree'
  78. };
  79. this);
  80. if(!root){
  81. root=newExt.tree.AsyncTreeNode({
  82. id:'0',108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> text:"系统菜单"
  83. if(!nav){
  84. nav=newExt.tree.TreePanel({
  85. title:"左部导航",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> width:232,248); line-height:18px"> autoScroll: animate: loader:loader,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> root:root,248); line-height:18px"> enableDD: listeners:{
  86. 'click':function(node,event){
  87. if(!node.isLeaf()){
  88. //为目录节点时,点击不进入链接
  89. event.stopEvent();
  90. //事件:添加右键菜单
  91. nav.on("contextmenu",153); background-color:inherit; font-weight:bold">this.showTreeMenu);
  92. //事件:当节点文本改变时触发异步更新标题
  93. nav.on("textchange",newText,oldText){
  94. if(!titleChangeFlag&&newText!=oldText){
  95. mgr.ajaxUpdateTitle(node.id,153); background-color:inherit; font-weight:bold">function(success){
  96. if(!success){
  97. Ext.Msg.show({
  98. title:"操作失败!",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> msg:"菜单修改失败!",248); line-height:18px"> buttons:Ext.Msg.OK,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> icon:Ext.MessageBox.ERROR
  99. titleChangeFlag=true;
  100. node.setText(oldText);
  101. //事件:当节点移动时触发
  102. nav.on("movenode",153); background-color:inherit; font-weight:bold">function(tree,node,oldParent,newParent,index){
  103. mgr.ajaxMoveNode(node.id,oldParent.id,newParent.id,index);
  104. //事件:当节点删除时触发
  105. nav.on("remove",parentNode,153); background-color:inherit; font-weight:bold">if(removeFlag){
  106. mgr.ajaxRemoveNode(node.id);
  107. /*事件:节点选中单击编辑
  108. if(!navEditor){
  109. navEditor=newExt.tree.TreeEditor(nav,0); background-color:inherit">allowBlank:false,0); background-color:inherit">ignoreNoChange:true,0); background-color:inherit">completeOnEnter:true,0); background-color:inherit">blankText:'标题不能为空',0); background-color:inherit">selectOnFocus:true
  110. });
  111. }*/
  112. this.setLeafMenu();//设置叶子菜单
  113. this.setDirMenu();//设置目录菜单
  114. setMgr:function(manager){
  115. mgr=manager;
  116. getMgr:returnmgr;
  117. //设置叶子菜单
  118. setLeafMenu:if(!leafMenu){
  119. leafMenu=newExt.menu.Menu({
  120. items:[{
  121. text:"修改标题",248); line-height:18px"> handler: navEditor=newExt.tree.TreeEditor(nav,248); line-height:18px"> allowBlank:false,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> ignoreNoChange: completeOnEnter: blankText:'标题不能为空',248); line-height:18px"> selectOnFocus: navEditor.triggerEdit(nodeSelected);
  122. "-",{
  123. text:"编辑",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> FormEditWin.showEditLeafWin(nodeSelected);
  124. text:"删除",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> handler:this.delTreeItemComfirm
  125. }]
  126. setDirMenu:if(!dirMenu){
  127. dirMenu= FormEditWin.showEditDirWin(nodeSelected);
  128. text:"添加叶子节点",248); line-height:18px"> FormEditWin.showAddLeafWin(nodeSelected);
  129. text:"添加目录节点",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> FormEditWin.showAddDirWin(nodeSelected);
  130. showTreeMenu: nodeSelected=node;
  131. nodeSelected.select();
  132. if(node.isLeaf()){
  133. //显示叶子节点菜单
  134. leafMenu.showAt(e.getPoint());
  135. }else{
  136. //显示目录节点菜单
  137. dirMenu.showAt(e.getPoint());
  138. delTreeItemComfirm: Ext.Msg.confirm("确认删除","确定要删除所选节点吗?",153); background-color:inherit; font-weight:bold">function(btn){
  139. if(btn=="yes"){
  140. NavTree.delTreeItem();
  141. delTreeItem:if(nodeSelected!=nav.getRootNode()){
  142. removeFlag=true;
  143. nodeSelected.remove();
  144. }else{
  145. Ext.Msg.alert("警告","不能删除树的根节点!");
  146. show: nav.render(Ext.getBody());
  147. nav.getRootNode().toggle();
  148. }();
  149. //文档加载完毕执行
  150. Ext.onReady( Ext.BLANK_IMAGE_URL="../scripts/ext/resources/images/default/s.gif";
  151. typeof(NavigateManager)=="undefined"){
  152. "请先设置DWR,并实例化NavigateManager");
  153. NavTree.setMgr(NavigateManager);
  154. NavTree.init();
  155. NavTree.show();
  156. });

servlet 配置:

[html] copy
    <?xmlversion="1.0"encoding="UTF-8"?>
  1. <web-appversion="2.4"
  2. xmlns="http://java.sun.com/xml/ns/j2ee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  5. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  6. servlet>
  7. servlet-name>navigatejson</servlet-class com.demo.navigate.web.NavigateJsonServlet
  8. >navigateedit com.demo.navigate.web.NavigateEditServlet
  9. >navigatesave com.demo.navigate.web.NavigateSaveServlet
  10. servlet-mappingurl-pattern>/navigatejson>/navigateedit>/navigatesave>dwr-invoker>uk.ltd.getahead.dwr.DWRServletinit-paramparam-name>debugparam-value>true allowGetForSafariButMakeForgeryEasier
  11. load-on-startup>1>/dwr/*welcome-file-listwelcome-file>index.jspweb-app>


DWR配置:

copy
    <!DOCTYPEdwrPUBLIC"-//GetAheadLimited//DTDDirectWebRemoting2.0//EN""http://www.getahead.ltd.uk/dwr//dwr20.dtd"dwrallowcreatejavascript="NavigateManager"creator="new"paramname="class"
  1. value="com.demo.navigate.service.NavigateManager"paramincludemethod="ajaxUpdateTitle"/>
  2. includemethod="ajaxRemoveNode"/>
  3. includemethod="ajaxMoveNode"create>


servlet程序:

[java] copy
    packagecom.demo.navigate.web;
  1. importjava.io.IOException;
  2. importjavax.servlet.RequestDispatcher;
  3. importjavax.servlet.ServletException;
  4. importjavax.servlet.http.HttpServlet;
  5. importjavax.servlet.http.HttpServletRequest;
  6. importjavax.servlet.http.HttpServletResponse;
  7. importcom.demo.navigate.model.Navigate;
  8. importcom.demo.navigate.service.NavigateManager;
  9. @SuppressWarnings("serial")
  10. publicclassNavigateSaveServletextendsHttpServlet{
  11. voiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
  12. throwsServletException,IOException{
  13. this.doPost(request,response);
  14. voiddoPost(HttpServletRequestrequest,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> NavigateManagernavigateManager=newNavigateManager();
  15. Navigateobj=null;
  16. request.setCharacterEncoding("UTF-8");
  17. Stringid=request.getParameter("id");
  18. Stringnumber=request.getParameter("number");
  19. StringparentId=request.getParameter("parentId");
  20. Stringleaf=request.getParameter("leaf");
  21. Stringtitle=request.getParameter("title");
  22. Stringurl=request.getParameter("url");
  23. null!=id&&!"".equals(id)){
  24. obj=navigateManager.get(id);
  25. if(obj==null){
  26. RequestDispatcherdispatcher=request.getRequestDispatcher("/navigate/error.jsp");
  27. dispatcher.forward(request,response);
  28. return;
  29. obj=newNavigate();
  30. obj.setLeaf(newInteger(leaf));
  31. obj.setParentId(newInteger(parentId));
  32. obj.setNumber(newInteger(number));
  33. obj.setTitle(title);
  34. obj.setUrl(url);
  35. null!=id&&!"".equals(id)){
  36. navigateManager.update(obj);
  37. navigateManager.save(obj);
  38. RequestDispatcherdispatcher=request.getRequestDispatcher("/navigate/success.jsp");
  39. dispatcher.forward(request,response);
  40. }
copy
    importcom.demo.navigate.service.NavigateManager;
  1. @SuppressWarnings("serial")
  2. classNavigateJsonServletextendsHttpServlet{
  3. NavigateManagernavigateManager=newNavigateManager();
  4. request.setAttribute("list",navigateManager.getChildrenById(newInteger(request.getParameter("id"))));
  5. RequestDispatcherdispatcher=request.getRequestDispatcher("/navigate/console-json.jsp");
  6. }
copy
    classNavigateEditServlet Stringidstr=request.getParameter("id");
  1. Stringnumber=request.getParameter("number");
  2. Navigateobj=null;
  3. null!=idstr){
  4. obj=navigateManager.get(idstr);
  5. obj=newNavigate();
  6. request.setAttribute("obj",obj);
  7. RequestDispatcherdispatcher=request.getRequestDispatcher("/navigate/console-edit.jsp");
  8. }


service程序:

copy
    packagecom.demo.navigate.service;
  1. importjava.io.Serializable;
  2. importjava.util.List;
  3. importcom.demo.navigate.dao.NavigateDao;
  4. classNavigateManager{
  5. privateNavigateDaodao=NavigateDao.getInstanece();
  6. publicNavigateget(Serializableid){
  7. returndao.get(id);
  8. /**
  9. *获得指定节点的所有儿子节点
  10. *@paramid
  11. */
  12. @SuppressWarnings("unchecked")
  13. publicList<Navigate>getChildrenById(Integerid){
  14. returndao.getChildrenById(id);
  15. *保存数据
  16. *@paramobj
  17. voidsave(Navigateobj){
  18. dao.save(obj);
  19. /**
  20. *更新数据
  21. *@paramobj
  22. */
  23. voidupdate(Navigateobj){
  24. dao.update(obj);
  25. *删除指定的一条数据
  26. voidremoveById(Integerid){
  27. dao.removeById(id);
  28. *异步更新标题
  29. *@paramid
  30. *@paramtitle
  31. *@returntrue-修改成功false-修改失败
  32. publicBooleanajaxUpdateTitle(Integerid,Stringtitle){
  33. returndao.ajaxUpdateTitle(id,title);
  34. *异步删除数据,包括其子孙节点
  35. *@paramtitle
  36. voidajaxRemoveNode(Integerid){
  37. Navigateobj=dao.get(id);
  38. dao.downNode(obj.getParentId(),obj.getNumber(),-1);
  39. dao.ajaxRemoveNode(id);
  40. *异步移动指定节点
  41. *@paramid指定的节点的id
  42. *@paramoldParentId节点移动前所在的父节点
  43. *@paramnewParentId节点移动后的目标父节点
  44. *@paramnodeIndex节点移动后的目标位置
  45. voidajaxMoveNode(intid,153); background-color:inherit; font-weight:bold">intoldParentId,153); background-color:inherit; font-weight:bold">intnewParentId,153); background-color:inherit; font-weight:bold">intnodeIndex){
  46. dao.ajaxMoveNode(id,oldParentId,newParentId,nodeIndex);
  47. }


model程序:


copy
    packagecom.demo.navigate.model;
  1. classNavigate{
  2. privateIntegerid;
  3. privateIntegerparentId;
  4. privateStringtitle;
  5. privateIntegernumber;
  6. privateIntegerleaf;
  7. privateStringurl;
  8. publicIntegergetId(){
  9. returnid;
  10. voidsetId(Integerid){
  11. this.id=id;
  12. publicIntegergetParentId(){
  13. returnparentId;
  14. voidsetParentId(IntegerparentId){
  15. this.parentId=parentId;
  16. publicStringgetTitle(){
  17. returntitle;
  18. voidsetTitle(Stringtitle){
  19. this.title=title;
  20. publicIntegergetNumber(){
  21. returnnumber;
  22. voidsetNumber(Integernumber){
  23. this.number=number;
  24. publicIntegergetLeaf(){
  25. returnleaf;
  26. voidsetLeaf(Integerleaf){
  27. this.leaf=leaf;
  28. publicStringgetUrl(){
  29. returnurl;
  30. voidsetUrl(Stringurl){
  31. this.url=url;
  32. }


Dao程序:

copy
    packagecom.demo.navigate.dao;
  1. importjava.sql.Connection;
  2. importjava.sql.ResultSet;
  3. importjava.sql.sqlException;
  4. importjava.sql.Statement;
  5. importjava.util.ArrayList;
  6. importjava.util.List;
  7. importcom.demo.core.dao.DBConn;
  8. importcom.demo.navigate.model.Navigate;
  9. classNavigateDao{
  10. privatestaticNavigateDaodao;
  11. privateNavigateDao(){
  12. staticNavigateDaogetInstanece(){
  13. null==dao){
  14. dao=newNavigateDao();
  15. returndao;
  16. *获得指定ID的数据
  17. *@return
  18. Connectionconection= Statementstmt= ResultSetrs=try{
  19. conection=DBConn.getConnection();
  20. stmt=conection.createStatement();
  21. StringBuffersql=newStringBuffer("select*fromnavigatewhereid=");
  22. sql.append(id);
  23. rs=stmt.executeQuery(sql.toString());
  24. if(rs.next())
  25. {
  26. obj.setId(rs.getInt("id"));
  27. obj.setLeaf(rs.getInt("leaf"));
  28. obj.setNumber(rs.getInt("number"));
  29. obj.setParentId(rs.getInt("parentId"));
  30. obj.setTitle(rs.getString("title"));
  31. obj.setUrl(rs.getString("url"));
  32. catch(Exceptione){
  33. e.printStackTrace();
  34. finally{
  35. try{
  36. if(rs!=null){
  37. rs.close();
  38. catch(sqlExceptione){
  39. rs=if(stmt!= stmt.close();
  40. catch(sqlExceptionsqlex){
  41. stmt=if(conection!= conection.close();
  42. catch(sqlExceptionsqlex){
  43. conection=catch(Exceptione){
  44. e.printStackTrace();
  45. returnobj;
  46. List<Navigate>list=newArrayList<Navigate>();
  47. Connectionconection= Statementstmt= ResultSetrs=newStringBuffer("select*fromnavigatewhereparentId=");
  48. sql.append("orderbynumber,id");
  49. System.out.println("首页加载树sql=="+sql.toString());
  50. while(rs.next())
  51. list.add(obj);
  52. finally{
  53. rs.close();
  54. catch(sqlExceptione){
  55. rs= stmt.close();
  56. stmt= conection.close();
  57. conection=returnlist;
  58. *保存数据
  59. voidsave(Navigateobj){
  60. StringBuffersql=newStringBuffer("insertintonavigate(parentId,title,leaf,number,url)values(");
  61. sql.append(obj.getParentId());
  62. sql.append(",'");
  63. sql.append(obj.getTitle());
  64. sql.append("',");
  65. sql.append(obj.getLeaf());
  66. sql.append(obj.getNumber());
  67. sql.append(obj.getUrl());
  68. sql.append("')");
  69. this.bulkUpdate(sql.toString());
  70. *更新数据
  71. voidupdate(Navigateobj){
  72. newStringBuffer("updatenavigateset");
  73. sql.append("parentId=");
  74. sql.append("title='");
  75. sql.append(obj.getTitle());
  76. sql.append("',");
  77. sql.append("leaf=");
  78. sql.append("number=");
  79. sql.append(obj.getNumber());
  80. sql.append(",url='");
  81. sql.append(obj.getUrl());
  82. sql.append("'whereid=");
  83. sql.append(obj.getId());
  84. *异步更新标题
  85. *@returntrue-修改成功false-修改失败
  86. Booleanflag=this.get(id);
  87. null!=obj){
  88. newStringBuffer("updatenavigateset");
  89. sql.append(title);
  90. sql.append("'");
  91. sql.append("whereid=");
  92. sql.append(id);
  93. this.bulkUpdate(sql.toString());
  94. flag=returnflag;
  95. newStringBuffer("deletefromnavigatewhereid=");
  96. @SuppressWarnings("unchecked")
  97. voidajaxRemoveNode(Integerid){
  98. Listlist=this.getChildrenById(id);
  99. for(Objectobject:list){
  100. Navigateobj=(Navigate)object;
  101. ajaxRemoveNode(obj.getId());
  102. this.removeById(id);
  103. *移动指定节点
  104. *@paramid指定的节点的id
  105. *@paramoldParentId节点移动前所在的父节点
  106. *@paramnewParentId节点移动后的目标父节点
  107. *@paramnodeIndex节点移动后的目标位置
  108. intnodeIndex){
  109. this.get(id);
  110. intminIndex=obj.getNumber().intValue();
  111. intmaxIndex=nodeIndex;
  112. if(oldParentId==newParentId&&minIndex!=maxIndex){
  113. //在同一个父节点下发生移动
  114. if(minIndex<maxIndex){
  115. //当要移动的节点的序号小于要移动到的目标序号,则下移
  116. this.downNode(oldParentId,minIndex,maxIndex);
  117. elseif(minIndex>maxIndex){
  118. //当要移动的节点的序号大于要移动到的目标序号,则上移
  119. maxIndex=minIndex;
  120. minIndex=nodeIndex;
  121. this.upNode(oldParentId,maxIndex);
  122. //节点本身的序号设置成要移动到的目标序号
  123. obj.setNumber(nodeIndex);
  124. this.update(obj);
  125. if(oldParentId!=newParentId){
  126. //在不同父节点下发生移动
  127. //1、相当于要移动的节点在原父节点下下移到最后再删除掉,因此要指定移动发生时节点所在的位置
  128. 1);
  129. //2、相当于要移动的节点在新父节点下上移到指定的位置,因此需要指定要移动到的位置
  130. this.upNode(newParentId,maxIndex,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> obj.setParentId(newParentId);
  131. this.update(obj);
  132. *指定的节点下移
  133. *@paramparentId指定范围内要移动的节点的父节点
  134. *@paramminIndex指定节点移动发生时所在的位置
  135. *@parammaxIndex指定节点要移动到的目标位置
  136. voiddownNode(intparentId,153); background-color:inherit; font-weight:bold">intminIndex,153); background-color:inherit; font-weight:bold">intmaxIndex){
  137. //指定的节点下移,意味着其范围内的节点各自减1
  138. newStringBuffer("updatenavigatesetnumber=number-1whereparentId=");
  139. sql.append(parentId);
  140. if(maxIndex!=-1){
  141. sql.append("andnumber<=");
  142. sql.append(maxIndex);
  143. if(minIndex!=- sql.append("andnumber>");
  144. sql.append(minIndex);
  145. *指定的节点上移
  146. *@paramparentId指定范围内要移动的节点的父节点
  147. *@paramminIndex指定节点要移动到的目标位置
  148. *@parammaxIndex指定节点移动发生时所在的位置
  149. voidupNode(intmaxIndex){
  150. //指定的节点上移,意味着其范围内的节点各自加1
  151. newStringBuffer("updatenavigatesetnumber=number+1whereparentId=");
  152. sql.append(parentId);
  153. 1){
  154. sql.append("andnumber<");
  155. sql.append(maxIndex);
  156. sql.append("andnumber>=");
  157. sql.append(minIndex);
  158. *批量更新或删除操作
  159. *@paramsql
  160. voidbulkUpdate(Stringsql){
  161. stmt.executeUpdate(sql);
  162. copy
      packagecom.demo.core.dao;
    1. importjava.sql.Connection;
    2. importjava.sql.DriverManager;
    3. classDBConn{
    4. staticStringurl="jdbc:MysqL://localhost:3306/langsin";
    5. staticStringusername="root";
    6. staticStringpassword="tiger";
    7. staticStringdriver="com.MysqL.jdbc.Driver";
    8. staticConnectiongetConnection(){
    9. Connectionconn= Class.forName(driver);
    10. conn=DriverManager.getConnection(url,username,password);
    11. returnconn;
    12. }


    数据库脚本:

    [sql] copy
      createtablenavigate(
    1. idintprimarykeyauto_increment,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> leafintnotnull,248); line-height:18px"> number parentId titlevarchar(50) urlvarchar(200)null
    2. );


    页面:

    copy
      <%@pagecontentType="text/html;charset=UTF-8"%<%
    1. Stringpath=request.getContextPath();
    2. StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    3. %>htmlheadtitle>导航控制linkrel="stylesheet"type="text/css"href="../scripts/ext/resources/css/ext-all.css"scripttype="text/javascript"src="<%=basePath%>/scripts/ext/adapter/ext/ext-base.js"scriptscripttype="text/javascript"src="<%=basePath%>/scripts/ext/ext-all.js"scripttype="text/javascript"src="<%=basePath%>/dwr/engine.js"scripttype="text/javascript"src="<%=basePath%>/dwr/util.js"scripttype="text/javascript"src="<%=basePath%>/dwr/interface/NavigateManager.js"scripttype="text/javascript" varglbRootPath="<%=basePath%>";
    4. scripttype="text/javascript"src="<%=basePath%>/scripts/navigate/console-index.js"body>
    原文链接:https://www.f2er.com/ajax/166808.html

    猜你在找的Ajax相关文章