bean
dao
util
action
class.js
class.jsp
tree.jsp
package com.lxit.struts.tree.bean.pojo; import org.apache.struts.action.ActionForm; public class Classlist extends ActionForm{ private String id; private String name; private String course; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } }
package com.lxit.struts.tree.bean.pojo; public class Purview { private String id; private String name; private String purview; private String rootId; private boolean leaf = true; private boolean checked = false; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPurview() { return purview; } public void setPurview(String purview) { this.purview = purview; } public String getRootId() { return rootId; } public void setRootId(String rootId) { this.rootId = rootId; } public boolean isLeaf() { return leaf; } public void setLeaf(String leaf) { this.leaf = Boolean.parseBoolean(leaf); } public boolean isChecked() { return checked; } public void setChecked(boolean checked) { this.checked = checked; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
dao
package com.lxit.struts.tree.dao; import com.lxit.struts.tree.bean.pojo.Classlist; public class ClassDao extends SuperDao<Classlist>{ public ClassDao(){ super(); } }package com.lxit.struts.tree.dao; public class FactoryManage { private FactoryManage(){} public static PurviewDao getPurviewDao(){ return new PurviewDao(); } public static ClassDao getClassDao(){ return new ClassDao(); } }
package com.lxit.struts.tree.dao;
import com.lxit.struts.tree.bean.pojo.Purview;
public class PurviewDao extends SuperDao<Purview>{
public PurviewDao(){
super();
}
}
package com.lxit.struts.tree.dao; import java.sql.SQLException; import java.util.List; import com.ibatis.sqlmap.client.SqlMapClient; import com.lxit.struts.tree.util.IbatisUtil; public abstract class SuperDao<T> { protected SqlMapClient sqlMapClient; public SuperDao(){ this.sqlMapClient = IbatisUtil.getSqlMapClient(); } public List<T> query(String sqlId){ List<T> list = null; try { list = sqlMapClient.queryForList(sqlId); } catch (SQLException e) { e.printStackTrace(); } return list; } public List<T> query(String sqlId,String nodeId){ List<T> list = null; try { list = sqlMapClient.queryForList(sqlId,nodeId); } catch (SQLException e) { e.printStackTrace(); } return list; } public Long getDataCount(String sqlId){ Long count = 0L; try { count = (Long)sqlMapClient.queryForObject(sqlId); } catch (SQLException e) { e.printStackTrace(); } return count; } public boolean add(String sqlId,T t){ boolean flag = true; try { sqlMapClient.insert(sqlId, t); } catch (SQLException e) { flag = false; e.printStackTrace(); } return flag; } public boolean update(String sqlId,T t){ boolean flag = true; try { sqlMapClient.update(sqlId, t); } catch (SQLException e) { flag = false; e.printStackTrace(); } return flag; } }
util
package com.lxit.struts.tree.util; import java.io.IOException; import java.io.Reader; import com.ibatis.common.resources.Resources; import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClientBuilder; public class IbatisUtil { private final static String RESOURCE = "SqlMapConfig.xml"; private static SqlMapClient sqlMapClient = null; private static Reader reader = null; public static SqlMapClient getSqlMapClient() { if(sqlMapClient == null){ try { reader = Resources.getResourceAsReader(RESOURCE); } catch (IOException e) { e.printStackTrace(); } sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader); } return sqlMapClient; } }
package com.lxit.struts.tree.util; import java.util.UUID; public class StringUtil { private StringUtil(){} public static String getUUID(){ return UUID.randomUUID().toString().replaceAll("-", ""); } }
action
package com.lxit.struts.tree.action; import java.io.IOException; 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; import com.lxit.struts.tree.bean.pojo.Classlist; import com.lxit.struts.tree.dao.ClassDao; import com.lxit.struts.tree.dao.FactoryManage; import com.lxit.struts.tree.util.StringUtil; public class AddClassAction extends Action{ private ClassDao classDao = FactoryManage.getClassDao(); @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { Classlist classlist = new Classlist(); classlist.setCourse(request.getParameter("course")); classlist.setName(request.getParameter("name")); classlist.setId(StringUtil.getUUID()); if(classDao.add("insertClass", classlist)){ setDataPage(response,"{success:true,msg:'添加成功!'}"); }else{ setDataPage(response,"{failure:false,msg:'操作失败!'}"); } return null; } private void setDataPage(HttpServletResponse response,String data) throws IOException{ response.setCharacterEncoding("UTF-8"); response.setContentType("text/hmtl"); PrintWriter printWriter = response.getWriter(); printWriter.print(data); printWriter.flush(); printWriter.close(); } }
package com.lxit.struts.tree.action; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.lxit.struts.tree.bean.pojo.Classlist; import com.lxit.struts.tree.dao.ClassDao; import com.lxit.struts.tree.dao.FactoryManage; public class ClassAction extends Action{ private ClassDao classDao = FactoryManage.getClassDao(); @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Classlist> purviewList = classDao.query("selectTableClass"); JSONObject jsonObject = new JSONObject(); jsonObject.put("count", classDao.getDataCount("selectCountClass")); jsonObject.put("rows", purviewList); setDataPage(response, jsonObject.toString()); return super.execute(mapping, form, request, response); } private void setDataPage(HttpServletResponse response,String data) throws IOException{ response.setCharacterEncoding("UTF-8"); response.setContentType("text/hmtl"); PrintWriter printWriter = response.getWriter(); printWriter.print(data); printWriter.flush(); printWriter.close(); } }
package com.lxit.struts.tree.action; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.lxit.struts.tree.bean.pojo.Purview; import com.lxit.struts.tree.dao.FactoryManage; import com.lxit.struts.tree.dao.PurviewDao; public class TreeAction extends Action{ private PurviewDao purviewDao = FactoryManage.getPurviewDao(); @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { List<Purview> purviewList = purviewDao.query("selectTablePurview",request.getParameter("node")); JSONObject jsonObject = new JSONObject(); jsonObject.put("rows", purviewList); setDataPage(response, jsonObject.toString()); return null; } private void setDataPage(HttpServletResponse response,String data) throws IOException{ response.setCharacterEncoding("UTF-8"); response.setContentType("text/hmtl"); PrintWriter printWriter = response.getWriter(); printWriter.print(data); printWriter.flush(); printWriter.close(); } }
package com.lxit.struts.tree.action; import java.io.IOException; 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; import com.lxit.struts.tree.bean.pojo.Classlist; import com.lxit.struts.tree.dao.ClassDao; import com.lxit.struts.tree.dao.FactoryManage; public class UpdateClassAction extends Action{ private ClassDao classDao = FactoryManage.getClassDao(); @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { Classlist classlist = new Classlist(); classlist.setId(request.getParameter("id")); classlist.setName(request.getParameter("name")); classlist.setCourse(request.getParameter("course")); if(classDao.update("updateClass", classlist)){ setDataPage(response,"{success:true,msg:'修改成功!'}"); }else{ setDataPage(response,"{failure:false,msg:'操作失败!'}"); } return null; } private void setDataPage(HttpServletResponse response,String data) throws IOException{ response.setCharacterEncoding("UTF-8"); response.setContentType("text/hmtl"); PrintWriter printWriter = response.getWriter(); printWriter.print(data); printWriter.flush(); printWriter.close(); } }
class.js
Ext.onReady(function(){ Ext.QuickTips.init(); var config = {column:[{header:'班级ID',dataIndex:'id',sortable:true}, {header:'班级名称',dataIndex:'name',sortable:true}, {header:'课程',dataIndex:'course',sortable:true} ],url:"class.do",autoLoad:true}; var classlist = new purviewGridPanel({ loadMask : {msg:'加载数据中...'}, tbar : ['->',{ text : '添加', id:'add', handler : function(){ window.show(); } },'-',{ text : '修改', id:'update', handler : function(){ var record = classlist.getSelections(); if(record.length > 0){ if(record.length == 1){ /*alert(classlist.getRecord()); updateClassForm.getForm().loadRecord(classlist.getRecord());*/ var r = classlist.getSelected(); Ext.getCmp("className_id").setValue(r.get("name")); Ext.getCmp("course_id").setValue(r.get("course")); win.show(); }else{ Ext.Msg.alert("提示","请选择一行数据进行修改!"); } }else{ Ext.Msg.alert("提示","请选中你要修改的行!"); } } }] },config); var updateClassForm = new Ext.form.FormPanel({ width : 320, height : 160, id : 'classForm', items:[{ xtype : 'textfield', fieldLabel : '班级名', name : 'name', id : 'className_id', allowBlank: false, width : 180, blankText : '班级名不能为空!' },{ xtype : 'textfield', fieldLabel : '班级名', name : 'course', id : 'course_id', allowBlank: false, width : 180, blankText : '课程名不能为空!' }], bbar : ['->',{ text : '提交', handler : function(){ var basicForm = updateClassForm.getForm(); if(basicForm.isValid()){ basicForm.submit( { url : 'updateClass.do', method : 'POST', params:{id:classlist.getSelected().get("id")}, success : function(r, action) { Ext.Msg.alert("提示",action.result.msg); classlist.getStore().reload(); }, failure : function(r, action) { Ext.Msg.alert("提示",action.result.msg); } }); win.hide(); }else{ Ext.msg.alert("提示","信息填写不完整!"); } } },'-',{ text : '重置', handler : function(){ updateClassForm.getForm().reset(); } }] }); var win = new Ext.Window({ title : '班级管理', width : 335, height : 190, resizable : false, modal : true, closeAction : 'hide', items : [updateClassForm] }); var classForm = new Ext.form.FormPanel({ width : 320, height : 160, id : 'classForm', items:[{ xtype : 'textfield', fieldLabel : '班级名', name : 'name', id : 'classNameId', allowBlank: false, width : 180, blankText : '班级名不能为空!' },{ xtype : 'textfield', fieldLabel : '班级名', name : 'course', id : 'courseId', allowBlank: false, width : 180, blankText : '课程名不能为空!' }], bbar : ['->',{ text : '提交', handler : function(){ var basicForm = classForm.getForm(); if(basicForm.isValid()){ basicForm.submit( { url : 'addClass.do', method : 'POST', success : function(r, action) { Ext.Msg.alert("提示",action.result.msg); classlist.getStore().reload(); }, failure : function(r, action) { Ext.Msg.alert("提示",action.result.msg); } }); window.hide(); }else{ Ext.msg.alert("提示","信息填写不完整!"); } } },'-',{ text : '重置', handler : function(){ classForm.getForm().reset(); } }] }); var window = new Ext.Window({ title : '班级管理', width : 335, height : 190, resizable : false, modal : true, closeAction : 'hide', items : [classForm] }); var panel = new Ext.Panel({ title : '班级管理', layout:'fit', items : [classlist] }); new Ext.Viewport({ layout:'fit', renderTo:Ext.getBody(), items:[panel] }); });
purviewGridPanel = function(view,config){ Ext.apply(this,view); this.init(config); this.bbar=new Ext.PagingToolbar({ store:this.store, pageSize:15, emptyMsg:'没有数据显示', displayInfo:true, displayMsg :"显示{0} - {1}条,共{2}数据" }); purviewGridPanel.superclass.constructor.call(this,{}); }; Ext.extend(purviewGridPanel,Ext.grid.GridPanel,{ init : function(config){ var sm = new Ext.grid.CheckboxSelectionModel(); var c =[new Ext.grid.RowNumberer(),sm],r=[]; for(var i=0,j=config.column.length;i<j;i++){ var ct = config.column[i]; c.push(config.column[i]); r.push({name:config.column[i].dataIndex}); } this.columns=c; this.record = r; this.store = new Ext.data.Store({ url:config.url, autoLoad:config.autoLoad, baseParams:{start:0,limit:15}, reader:new Ext.data.JsonReader({ totalProperty:'count', root:'rows' },Ext.data.Record.create(r)) }); }, getRecord:function(){ return this.record; }, getSelected:function(){ return this.getSelectionModel().getSelected(); }, getStore:function(){ return this.store; }, getSelections:function(){ return this.getSelectionModel().getSelections(); } });
Ext.onReady(function(){ var tree = new Ext.tree.TreePanel({ loader: new Ext.tree.TreeLoader({ dataUrl:'tree.do', processResponse : function(response, node, callback, scope){ var json = response.responseText; try { var b = response.responseData || Ext.decode(json); var o = b.rows; node.beginUpdate(); for(var i = 0, len = o.length; i < len; i++){ var n = this.createNode({ id:o[i].id, text:o[i].name, //checked:o[i].checked, leaf:o[i].leaf }); if(n){ node.appendChild(n); } } node.endUpdate(); this.runCallback(callback, scope || node, [node]); }catch(e){ this.handleFailure(response); } } }), root:new Ext.tree.AsyncTreeNode({id:'47eb9fa557924553b197c47a249f336f',text:'系统权限'}), rootVisible:true, autoScroll : true, border : false, width:150, height:310, id:'roleTree', bufferResize : 250 }); var panel = new Ext.Panel({ title : '权限管理界面', layout:'fit', items : [tree] }); new Ext.Viewport({ layout:'fit', renderTo:Ext.getBody(), items:[panel] }); });
class.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="ext/resources/css/ext-all.css"></link> <script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext/ext-all.js"></script> <script type="text/javascript" src="tree/js/super.js"></script> <script type="text/javascript" src="tree/js/class.js"></script> <title>Insert title here</title> </head> <body> </body> </html>
tree.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="ext/resources/css/ext-all.css"></link> <script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext/ext-all.js"></script> <script type="text/javascript" src="tree/js/tree.js"></script> <title>测试树</title> </head> <body> </body> </html>
相关推荐
### Struts1与Struts2的主要区别 #### 概述 Apache Struts 是一个用于构建企业级Java Web应用的开源框架。它分为两个版本:Struts1 和 Struts2。虽然两者都基于模型-视图-控制器(MVC)设计模式,但它们之间存在...
Struts 2整合Struts 1,允许开发者利用Struts 1已有的投资,同时享受Struts 2带来的优势,如增强的类型安全和更强大的拦截器机制。 在《Struts 2权威指南--基于WebWork核心的MVC开发》这本书中,作者李纲深入浅出地...
Struts1和Struts2是两个非常著名的Java Web框架,它们都由Apache软件基金会开发,用于构建MVC(Model-View-Controller)架构的应用程序。虽然它们在目标上相似,但在设计模式、功能特性和使用体验上存在显著差异。...
Struts1和Struts2是两个不同的版本,它们各自拥有独特的特性和功能,但在Java Web开发领域都扮演了重要角色。 **Struts1** Struts1是最早的版本,它在2001年发布,是基于ApacheJakarta项目的一个框架。Struts1的...
Struts 1.x 是一款基于模型-视图-控制器(MVC)设计模式的Java Web框架,它在早期的Web应用程序开发中占据了重要的地位。本教程主要针对初学者,旨在引导学习者掌握Struts 1.x的基础知识和使用方法。 在开始学习...
Struts1是一个经典的Java Web框架,它为开发者提供了一种结构化的MVC(Model-View-Controller)设计模式实现方式。然而,在Struts1的原生设计中,并没有内置拦截器(Interceptor)这一概念,这与后来的Struts2框架...
Struts1是一个经典的Java Web开发框架,由Apache软件基金会维护,它主要负责处理MVC(Model-View-Controller)架构中的控制器部分。本实验项目旨在帮助开发者深入理解Struts1的核心概念和工作流程,以便更好地在实际...
Struts1和Struts2是两个非常著名的Java Web框架,它们在设计模式、可测试性、输入处理和表现层等方面存在显著的区别。 首先,Action类的设计有所不同。在Struts1中,Action类需要继承一个抽象基类,这限制了Action...
### Struts1与Struts2的主要区别 #### 一、Action执行机制的不同 - **Struts1**: 在Struts1框架中,Action是基于单例模式的,这意味着所有的请求都会共享同一个Action实例。这就导致了如果在Action中保存实例变量...
这个压缩包包含了两个关键版本的Struts框架的电子书,即Struts1.x和Struts2.0的相关资料。 **Struts1.x** Struts1.x是最初的Struts版本,它极大地简化了Java Servlet和JSP的应用开发。Struts1的核心概念包括Action...
struts1 和 struts2所需jar包。主要包含以下内容: struts-1.3.10-all.zip struts-1.3.10-apps.zip struts-1.3.10-lib.zip struts-1.3.10-src.zip struts-2.3.4.1-all.zip struts.rar
Struts1是一个经典的Java Web开发框架,它引入了模型-视图-控制器(MVC)设计模式,使得开发者能够更有效地组织和管理Web应用程序。在本样例程序中,我们结合了Struts1与Maven,后者是一个项目管理和集成工具,能够...
Struts2是Struts1的升级版,它在Struts1的基础上引入了许多改进和新特性,提高了开发效率和应用性能。 Struts1是一个经典的MVC框架,它的核心组件包括Action、Form Bean、Action Mapping和Tiles等。Action是业务...
Struts1是一个经典的Java Web开发框架,由Apache软件基金会维护,它基于Model-View-Controller(MVC)设计模式,极大地简化了Java Servlet和JSP的开发。在本项目中,“struts1项目代码”提供了从头到尾的实现,包括...
Struts1和Struts2是两个非常重要的Java Web框架,由Apache软件基金会开发,用于构建MVC(模型-视图-控制器)架构的应用程序。它们极大地简化了Web应用的开发,提高了代码的可维护性和组织性。 Struts1是早期的版本...
这里提到的"struts1和struts2相关jar包"分别指的是Struts框架的两个主要版本:Struts 1和Struts 2。 **Struts 1** Struts 1是最早的版本,于2000年发布。它是基于Java Servlet和JSP技术的,旨在解决在JSP应用中控制...
因为最近攻防演练,对公司的资产进行梳理,发现部分应用还使用的struts1框架,所以赶快收集整理了相关的漏洞以及相关的整改方案。提供给大家。
Struts1是一个经典的Java Web开发框架,而Apache POI是一个流行的API,用于处理Microsoft Office格式的文件,包括Excel。在本项目中,"struts1 poi Excel批量导入支持xls和xlsx"是一个基于Struts1和POI实现的功能,...
本项目为基于Java语言的Struts1框架设计的struts1Demo项目源码,包含55个文件,涵盖23个JAR包、10个Java源文件、6个JSP文件、4个XML配置文件及其他类型文件。