首页 > 代码库 > oracle+servlet+extjs4 分页表格布局示例代码
oracle+servlet+extjs4 分页表格布局示例代码
Log.java
1 package com.example.entity; 2 3 import java.util.Date; 4 5 public class Log { 6 7 private int id; 8 private Date timestamp; 9 private String module; 10 private String function; 11 private String method; 12 private String userId; 13 private String userName; 14 private String localIp; 15 private String remoteIp; 16 private int type; 17 private String fileName; 18 private int fileSize; 19 private String params; 20 private int success; 21 private String error; 22 public String getError() { 23 return error; 24 } 25 public void setError(String error) { 26 this.error = error; 27 } 28 public String getFileName() { 29 return fileName; 30 } 31 public void setFileName(String fileName) { 32 this.fileName = fileName; 33 } 34 public int getFileSize() { 35 return fileSize; 36 } 37 public void setFileSize(int fileSize) { 38 this.fileSize = fileSize; 39 } 40 public String getFunction() { 41 return function; 42 } 43 public void setFunction(String function) { 44 this.function = function; 45 } 46 public int getId() { 47 return id; 48 } 49 public void setId(int id) { 50 this.id = id; 51 } 52 public String getLocalIp() { 53 return localIp; 54 } 55 public void setLocalIp(String localIp) { 56 this.localIp = localIp; 57 } 58 public String getMethod() { 59 return method; 60 } 61 public void setMethod(String method) { 62 this.method = method; 63 } 64 public String getModule() { 65 return module; 66 } 67 public void setModule(String module) { 68 this.module = module; 69 } 70 public String getParams() { 71 return params; 72 } 73 public void setParams(String params) { 74 this.params = params; 75 } 76 public String getRemoteIp() { 77 return remoteIp; 78 } 79 public void setRemoteIp(String remoteIp) { 80 this.remoteIp = remoteIp; 81 } 82 public int getSuccess() { 83 return success; 84 } 85 public void setSuccess(int success) { 86 this.success = success; 87 } 88 public Date getTimestamp() { 89 return timestamp; 90 } 91 public void setTimestamp(Date timestamp) { 92 this.timestamp = timestamp; 93 } 94 public int getType() { 95 return type; 96 } 97 public void setType(int type) { 98 this.type = type; 99 }100 public String getUserId() {101 return userId;102 }103 public void setUserId(String userId) {104 this.userId = userId;105 }106 public String getUserName() {107 return userName;108 }109 public void setUserName(String userName) {110 this.userName = userName;111 }112 113 }
LogDAO.java
1 package com.example.DAO; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 import java.sql.PreparedStatement; 6 import java.sql.ResultSet; 7 import java.sql.SQLException; 8 import java.util.ArrayList; 9 import java.util.List;10 11 12 import com.example.entity.Log;13 14 15 public class LogDAO {16 17 private static Connection getConn() {18 String driver = "oracle.jdbc.driver.OracleDriver";19 String url = "jdbc:oracle:thin:@192.168.97.201:1521:fznop";20 String username = "bi_swxt";21 String password = "swxt2013";22 Connection conn = null;23 try {24 Class.forName(driver);25 // new oracle.jdbc.driver.OracleDriver();26 conn = DriverManager.getConnection(url, username, password);27 }28 catch (ClassNotFoundException e) {29 e.printStackTrace();30 }31 catch (SQLException e) {32 e.printStackTrace();33 }34 35 return conn;36 }37 38 public static List<Log> findAll(int start, int limit) {39 int s = start +1;40 int e = start + limit;41 Connection conn = getConn();42 String sql = "select id,timestamp,module,function,method,user_id,user_name,local_ip," +43 "remote_ip,type,file_name,file_size,params,success,error from (select r.*, rownum as d " +44 "from (select * from system_log) r where rownum <= " +e + ") where d >= " +s;45 PreparedStatement pstmt;46 List<Log> list = new ArrayList<Log>();47 48 try {49 pstmt = conn.prepareStatement(sql);50 ResultSet rs = pstmt.executeQuery();51 while (rs.next()) {52 Log log = new Log();53 log.setId(rs.getInt(1));54 log.setTimestamp(rs.getDate(2));55 log.setModule(rs.getString(3));56 log.setFunction(rs.getString(4));57 log.setMethod(rs.getString(5));58 log.setUserId(rs.getString(6));59 log.setUserName(rs.getString(7));60 log.setLocalIp(rs.getString(8));61 log.setRemoteIp(rs.getString(9));62 log.setType(rs.getInt(10));63 log.setFileName(rs.getString(11));64 log.setFileSize(rs.getInt(12));65 log.setParams(rs.getString(13));66 log.setSuccess(rs.getInt(14));67 log.setError(rs.getString(15));68 list.add(log);69 }70 rs.close();71 pstmt.close();72 conn.close();73 } catch (SQLException e1) {74 e1.printStackTrace();75 } 76 return list;77 }78 79 public static int getTotal(){80 Connection conn = getConn();81 String sql = " select count(*) from system_log";82 PreparedStatement pstmt;83 int total = 0;84 try {85 pstmt = conn.prepareStatement(sql);86 ResultSet rs = pstmt.executeQuery();87 if(rs.next()){88 total= rs.getInt(1);89 }90 } catch (SQLException e) {91 // TODO Auto-generated catch block92 e.printStackTrace();93 }94 return total;95 }96 }
LogServlet.java
1 package com.example.servlet; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 import java.util.List; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest;10 import javax.servlet.http.HttpServletResponse;11 12 import com.example.DAO.LogDAO;13 import com.example.entity.Log;14 15 public class LogServlet extends HttpServlet {16 17 private static final long serialVersionUID = -4798851845756886622L;18 19 @Override20 protected void doGet(HttpServletRequest req, HttpServletResponse resp)21 throws ServletException, IOException {22 int start = Integer.parseInt(req.getParameter("start"));23 int limit = Integer.parseInt(req.getParameter("limit"));24 LogDAO logDAO = new LogDAO();25 List<Log> list = logDAO.findAll(start , limit);26 int total = logDAO.getTotal();27 StringBuilder sb = new StringBuilder();28 sb.append("{results: " + total + ", rows:[");29 for (Log log : list) {30 sb.append("{");31 sb.append("ID : " + log.getId());32 sb.append(", TIMESTAMP : \‘" + log.getTimestamp() + "\‘");33 sb.append(", MODULE : \‘" + log.getModule() + "\‘");34 sb.append(", FUNCTION : \‘" + log.getFunction() + "\‘");35 sb.append(", METHOD : \‘" + log.getMethod() + "\‘");36 sb.append(", USER_ID : \‘" + log.getUserId() + "\‘");37 sb.append(", USER_NAME : \‘" + log.getUserName() + "\‘");38 sb.append(", LOCAL_IP : \‘" + log.getLocalIp() + "\‘");39 sb.append(", REMOTE_IP : \‘" + log.getRemoteIp() + "\‘");40 sb.append(", TYPE : " + log.getType());41 sb.append(", FILE_NAME : \‘" + log.getFileName() + "\‘");42 sb.append(", FILE_SIZE : " + log.getFileSize());43 sb.append(", PARAMS : \‘" + log.getParams() + "\‘");44 sb.append(", SUCCESS : " + log.getSuccess());45 sb.append(", ERROR : \‘" + log.getError() + "\‘");46 sb.append("},");47 }48 49 String json = sb.substring(0, sb.length() - 1);50 51 json += "]}";52 resp.setContentType("text/html");53 resp.setCharacterEncoding("UTF-8");54 PrintWriter out = resp.getWriter();55 out.println(json);56 out.close();57 }58 59 }
grid.js
1 Ext.onReady(function(){ 2 var itemsPerPage = 10; 3 4 var store = Ext.create(‘Ext.data.Store‘,{ 5 autoLoad: {start: 0, limit: itemsPerPage}, 6 fields: [‘ID‘,‘TIMESTAMP‘,‘MODULE‘,‘FUNCTION‘,‘METHOD‘,‘USER_ID‘,‘USER_NAME‘ 7 ,‘LOCAL_IP‘,‘REMOTE_IP‘,‘TYPE‘,‘FILE_NAME‘,‘FILE_SIZE‘,‘PARAMS‘,‘SUCCESS‘,‘ERROR‘],//定义字段 8 pageSize: itemsPerPage, 9 proxy: {10 type: ‘ajax‘,11 url: ‘log.do‘, 12 reader: {13 type: ‘json‘,14 root: ‘rows‘,15 totalProperty: ‘results‘16 }17 }18 });19 //创建Grid表格组件20 Ext.create(‘Ext.grid.Panel‘,{21 title : ‘Grid表格示例‘,22 renderTo: Ext.getBody(),23 width:1300,24 height:330,25 frame:true,26 store: store,27 28 columns: [//配置表格列29 {header: "ID", width: 80, dataIndex: ‘ID‘, sortable: true},30 {header: "TIMESTAMP", width: 80, dataIndex: ‘TIMESTAMP‘, sortable: true},31 {header: "MODULE", width: 80, dataIndex: ‘MODULE‘, sortable: true},32 {header: "FUNCTION", width: 80, dataIndex: ‘FUNCTION‘, sortable: true},33 {header: "METHOD", width: 80, dataIndex: ‘METHOD‘, sortable: true},34 {header: "USER_ID", width: 80, dataIndex: ‘USER_ID‘, sortable: true},35 {header: "USER_NAME", width: 80, dataIndex: ‘USER_NAME‘, sortable: true},36 {header: "LOCAL_IP", width: 80, dataIndex: ‘LOCAL_IP‘, sortable: true},37 {header: "REMOTE_IP", width: 80, dataIndex: ‘REMOTE_IP‘, sortable: true},38 {header: "TYPE", width: 80, dataIndex: ‘TYPE‘, sortable: true},39 {header: "FILE_NAME", width: 80, dataIndex: ‘FILE_NAME‘, sortable: true},40 {header: "FILE_SIZE", width: 80, dataIndex: ‘FILE_SIZE‘, sortable: true},41 {header: "PARAMS", width: 80, dataIndex: ‘PARAMS‘, sortable: true},42 {header: "SUCCESS", width: 80, dataIndex: ‘SUCCESS‘, sortable: true},43 {header: "ERROR", width: 80, dataIndex: ‘ERROR‘, sortable: true}44 ],45 bbar:[{46 xtype: ‘pagingtoolbar‘,47 store: store,48 displayInfo: true,49 displayMsg: ‘显示第 {0} 条到 {1} 条记录,一共 {2} 条‘,50 emptyMsg: "当前查询条件无数据,请重新查询"51 }]52 });53 });
index.jsp
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <title>MyTestWeb</title> 5 <link type="text/css" rel="stylesheet" href="resource/common/extjs/resources/css/ext-all-neptune.css" /> 6 </head> 7 <body > 8 <script type="text/javascript" src="resource/common/extjs/ext-all.js"></script> 9 <script type="text/javascript" src="resource/common/extjs/locale/ext-lang-zh_CN.js"></script>10 <script type="text/javascript" src="resource/common/extjs/packages/ext-theme-neptune/build/ext-theme-neptune.js"></script>11 <script type="text/javascript" src="resource/grid/grid.js"></script>12 <%--<div >13 </div>14 --%></body>15 </html>
web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="2.4" 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 7 <servlet> 8 <servlet-name>Log</servlet-name> 9 <servlet-class>10 com.example.servlet.LogServlet11 </servlet-class>12 </servlet>13 <servlet-mapping>14 <servlet-name>Log</servlet-name>15 <url-pattern>/log.do</url-pattern>16 </servlet-mapping>17 18 <welcome-file-list>19 <welcome-file>index.jsp</welcome-file>20 </welcome-file-list>21 </web-app>
oracle+servlet+extjs4 分页表格布局示例代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。