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 block
92             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     @Override
20     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.LogServlet
11         </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>
时间: 2024-10-11 21:04:01

oracle+servlet+extjs4 分页表格布局示例代码的相关文章

3个简单的页面布局示例

示例代码 -1 (利用HTML5标签及浮动布局) <style> header nav ul { margin: 15px; list-style: none; height: 50px; } header nav ul li { font-size: 1.5em; color: coral; margin: 10px; float: left; } header nav ul li a { text-decoration: none; } aside { margin-right: 50px

一个非常标准的Java连接Oracle数据库的示例代码

最基本的Oracle数据库连接代码(只针对Oracle11g): 1.右键项目->构建路径->配置构建路径,选择第三项"库",然后点击"添加外部Jar",选择"D:\Oracle\app\oracle\product\11.2.0\server \jdbc\lib\ojdbc6_g.jar"(注:D:\Oracle为数据库的安装路径). 2.以下代码为非常标准的Oracle数据库连接代码示例: /** * 一个非常标准的连接Oracl

php分页函数示例代码,php分页代码实现方法

php分页函数示例代码 分享一例php分页函数代码,用此函数实现分页代码很不错. 代码,php分页函数. <?php /* * Created on 2011-07-28 * Author : LKK , http://lianq.net * 使用方法: require_once('mypage.php'); $result=mysql_query("select * from mytable", $myconn); $total=mysql_num_rows($result);

Java连接Oracle数据库的示例代码

最基本的Oracle数据库连接代码(只针对Oracle11g): 1.右键项目->构建路径 ->配置构建路径,选择第三项“库”,然后点击“添加外部Jar”,选择 “D:\Oracle\app\oracle\product\11.2.0\server \jdbc\lib\ojdbc6_g.jar”(注:D:\Oracle为数据库的安装路径). 2.以下代码为非常标准的Oracle数据库连接代码示例: /** * 一个非常标准的连接Oracle数据库的示例代码 */public void test

【转】一个非常标准的Java连接Oracle数据库的示例代码

原文地址: http://www.cnblogs.com/liuxianan/archive/2012/08/05/2624300.html 最基本的Oracle数据库连接代码(只针对Oracle11g): 1.右键项目->构建路径->配置构建路径,选择第三项“库”,然后点击“添加外部Jar”,选择“D:\Oracle\app\oracle\product\11.2.0\server \jdbc\lib\ojdbc6_g.jar”(注:D:\Oracle为数据库的安装路径). 2.以下代码为非

安卓表格布局android:collapseColumns,android:shrinkColumns和stretchColumn

TableLayout的行数由开发人员直接指定,即有多少个TableRow对象(或View控件),就有多少行. TableLayout的列数等于含有最多子控件的TableRow的列数.如第一TableRow含2个子控件,第二个TableRow含3个,第三个TableRow含4个,那么该TableLayout的列数为4. TableLayout可设置的属性包括全局属性及单元格属性. 1.全局属性也即列属性,有以下3个参数: android:stretchColumns    设置可伸展的列.该列可

2.2.3 TableLayout(表格布局)

本节引言: 前面我们已经学习了平时实际开发中用得较多的线性布局(LinearLayout)与相对布局(RelativeLayout), 其实学完这两个基本就够用了,笔者在实际开发中用得比较多的也是这两个,当然作为一个好学的程序猿, 都是喜欢刨根问题的,所以虽说用得不多,但是还是有必要学习一下基本的用法的,说不定哪一天能用得上呢! 你说是吧,学多点东西没什么的,又不吃亏!好了,扯淡就扯到这里,开始这一节的学习吧,这一节我们会学习 Android中的第三个布局:TableLayout(表格布局)!

基于CSS属性display:table的表格布局的使用

项目改造中遇到DIV+CSS实现的table,新需求需要在表格使用单元格合并,网上调查返现CSS display:table实现的table表格,没有单元格的属性和样式,经过一番思考,曲折现实了单元格的合并,即采用正行嵌套一个单独的display:table的DIV,然后在嵌套的表格DIV内部通过控制行列数和行列的高度,实现单元格合并.个人建议全新实现使用<table> HTML标签即可 一.CSS display属性的表格布局相关属性的解释: table    此元素会作为块级表格来显示(类

Android零基础入门第29节:善用TableLayout表格布局,事半功倍

前面学习了线性布局和相对布局,线性布局虽然方便,但如果遇到控件需要排列整齐的情况就很难达到要求,用相对布局又比较麻烦,为此Android系统中提供了表格布局. 一.认识TableLayout 表格布局就是让控件以表格的形式来排列控件,只要将控件放在单元格中,控件就可以整齐地排列,使用TableLayout标签. TableLayout继承了 LinearLayout,因此它的本质依然是线性布局管理器.每次向TableLayout中添加一个TableRow,该TableRow就是一个表格行,Tab