关于jui框架的java web分页刷新功能实现!

jsp页面部分代码:

头部:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3
 4       <%@ taglib prefix="s" uri="/struts-tags"%>
 5       <%@ page isELIgnored="false" %>
 6 <form id="pagerForm" method="post" action="infor/Name.do">
 7     <input type="hidden" name="pageNum" value="1" />
 8     <input type="hidden" name="numPerPage" value="${numPerPage}" />
 9     <input type="hidden" name="orderField" value="${orderField}" />
10     <input type="hidden" name="orderDirection" value="${orderDirection}" />
11 </form>

表格部分:

 1 <tbody>
 2         <s:iterator  value = "list">
 3             <tr target="sid_user" rel="1">
 4                 <td><input type="checkbox" name="ids" value="${id}"/></td>
 5                 <td>${nameID}</td>
 6                 <td>${name}</td>
 7                 <td>${moddate}</td>
 8                 <td>${modmanID}</td>
 9                 <td>${modmanName}</td>
10                 <td>
11                     <a title="编辑" target="dialog" href="infor/EditorName.do?flag=${id}" class="btnEdit" rel="EditorName">编辑</a>
12                 </td>
13             </tr>
14             </s:iterator>
15
16         </tbody>

底边分页部分:

 1 <div class="panelBar">
 2         <div class="pages">
 3             <span>每页</span>
 4                 <select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value})">
 5                 <option <s:if test="numPerPage==1">selected="selected"</s:if> value="1" >1</option>
 6
 7                 <option <s:if test="numPerPage==20">selected="selected"</s:if> value="20" >20</option>
 8                 <option <s:if test="numPerPage==50">selected="selected"</s:if> value="50">50</option>
 9                 <option <s:if test="numPerPage==100">selected="selected"</s:if> value="100">100</option>
10                 <option <s:if test="numPerPage==200">selected="selected"</s:if> value="200">200</option>
11             </select>
12             <span>条,共${totalCount}条</span>
13         </div>
14         <div class="pagination" targetType="${targetType}" totalCount="${totalCount}" numPerPage="${numPerPage}" pageNumShown="10" currentPage="${pageNum}"></div>
15     </div>

XML配置跳转(这个没必要参考):

<action name="Name" class="com.threegrand.www.information.action.Name" method="Name">
            <result  name="SUCCESS">/content/information/name.jsp</result>
        </action>

action层:

  1 import java.util.List;
  2 import java.util.Map;
  3
  4 import javax.servlet.http.HttpServletRequest;
  5
  6 import org.apache.struts2.ServletActionContext;
  7
  8 import com.opensymphony.xwork2.ActionSupport;
  9 import com.threegrand.www.information.service.NameService;
 10
 11 public class Name extends ActionSupport {
 12     NameService se = new NameService();
 13     private List<Map<String, Object>> list;
 14     private String name;
 15
 16     private String specimen;
 17     private String nameID;
 18     private String moddate;
 19     private String modmanID;
 20     private String modmanName;
 21     public NameService getSe() {
 22         return se;
 23     }
 24     public void setSe(NameService se) {
 25         this.se = se;
 26     }
 27     public String getName() {
 28         return name;
 29     }
 30     public void setName(String name) {
 31         this.name = name;
 32     }
 33     public List<Map<String, Object>> getList() {
 34         return list;
 35     }
 36     public void setList(List<Map<String, Object>> list) {
 37         this.list = list;
 38     }
 39     public String getSpecimen() {
 40         return specimen;
 41     }
 42     public void setSpecimen(String specimen) {
 43         this.specimen = specimen;
 44     }
 45     public String getNameID() {
 46         return nameID;
 47     }
 48     public void setNameID(String nameID) {
 49         this.nameID = nameID;
 50     }
 51     public String getModdate() {
 52         return moddate;
 53     }
 54     public void setModdate(String moddate) {
 55         this.moddate = moddate;
 56     }
 57     public String getModmanID() {
 58         return modmanID;
 59     }
 60     public void setModmanID(String modmanID) {
 61         this.modmanID = modmanID;
 62     }
 63     public String getModmanName() {
 64         return modmanName;
 65     }
 66     public void setModmanName(String modmanName) {
 67         this.modmanName = modmanName;
 68     }
 69
 70     /*
 71      * 分页刷新
 72      *
 73     */
 74
 75     private String loginName = "";
 76     private Integer pageNum=1;
 77     private Integer currentPage = 1; // 当前是第几页
 78     private String targetType="navTab"; // navTab或dialog,用来标记是navTab上的分页还是dialog上的分页
 79     private Integer totalCount=0; // 总条数
 80     private Integer numPerPage=20; // 每页显示多少条
 81     private Integer pageNumShown=10; // 页标数字多少个
 82     private Integer pageCount = 0; // 总页数
 83     private String orderField;
 84     private String orderDirection;
 85     public String getLoginName() {
 86         return loginName;
 87     }
 88     public void setLoginName(String loginName) {
 89         this.loginName = loginName;
 90     }
 91     public Integer getPageNum() {
 92         return pageNum;
 93     }
 94     public void setPageNum(Integer pageNum) {
 95         this.pageNum = pageNum;
 96     }
 97     public Integer getCurrentPage() {
 98         return currentPage;
 99     }
100     public void setCurrentPage(Integer currentPage) {
101         this.currentPage = currentPage;
102     }
103     public String getTargetType() {
104         return targetType;
105     }
106     public void setTargetType(String targetType) {
107         this.targetType = targetType;
108     }
109     public Integer getTotalCount() {
110         return totalCount;
111     }
112     public void setTotalCount(Integer totalCount) {
113         this.totalCount = totalCount;
114     }
115     public Integer getNumPerPage() {
116         return numPerPage;
117     }
118     public void setNumPerPage(Integer numPerPage) {
119         this.numPerPage = numPerPage;
120     }
121     public Integer getPageNumShown() {
122         return pageNumShown;
123     }
124     public void setPageNumShown(Integer pageNumShown) {
125         this.pageNumShown = pageNumShown;
126     }
127     public Integer getPageCount() {
128         return pageCount;
129     }
130     public void setPageCount(Integer pageCount) {
131         this.pageCount = pageCount;
132     }
133     public String getOrderField() {
134         return orderField;
135     }
136     public void setOrderField(String orderField) {
137         this.orderField = orderField;
138     }
139     public String getOrderDirection() {
140         return orderDirection;
141     }
142     public void setOrderDirection(String orderDirection) {
143         this.orderDirection = orderDirection;
144     }
145
146     public String Name(){
147         page();
148         list= se.pagination(loginName,pageNum,numPerPage,orderField,orderDirection);
149         return "SUCCESS";
150     }
151
152     public void page() {
153         totalCount = se.getCout(loginName);
154         pageCount = totalCount % numPerPage == 0 ? totalCount / numPerPage: totalCount / numPerPage + 1;
155     }
156
157     

service层:

 1 import java.sql.Connection;
 2 import java.sql.PreparedStatement;
 3 import java.sql.ResultSet;
 4 import java.sql.SQLException;
 5 import java.util.ArrayList;
 6 import java.util.List;
 7 import java.util.Map;
 8
 9 import javax.servlet.http.HttpServletRequest;
10 import org.apache.struts2.ServletActionContext;
11 import com.threegrand.www.utils.DBUtil;
12
13 public class NameService {
14     DBUtil db = new DBUtil();
15     List<Map<String,Object>> list;
16     /*
17      * 分页刷新
18      *
19     */
20
21     private Connection conn=null;
22     private PreparedStatement ps=null;
23     private ResultSet rs=null;
24
25     public Integer getCout(String name) {
26         int count=0;
27         try {
28             String sql="select count(1) from name where 1=1 and name like ?";
29             conn=db.getConnection();
30             ps=conn.prepareStatement(sql);
31             ps.setString(1,"%"+name+"%");
32             rs=ps.executeQuery();
33             if(rs.next()){
34                 count=rs.getInt(1);
35             }
36
37         } catch (SQLException e) {
38             e.printStackTrace();
39         }finally{
40             try {
41                 if (rs != null) {
42                     rs.close();
43                 }
44                 if (ps != null) {
45                     ps.close();
46                 }
47                 if (conn != null) {
48                     conn.close();
49                 }
50             } catch (SQLException e) {
51                 e.printStackTrace();
52             }
53         }
54         return count;
55     }
56     public List<Map<String, Object>> pagination(String name,Integer currentPage,Integer numPerPage,String orderField,String orderDirection){
57
58         String sql="SELECT id,specimen,nameID,name,moddate,modmanID,modmanName FROM name WHERE name LIKE ‘%%‘ limit "+(currentPage-1)*numPerPage +","+numPerPage;
59         if(orderField!=null&&!"".equals(orderField)){
60             sql="SELECT id,specimen,nameID,name,moddate,modmanID,modmanName FROM name WHERE name LIKE ‘%%‘ order by "+orderField+" "+orderDirection+" limit "+(currentPage-1)*numPerPage +","+numPerPage;
61
62         }
63
64         list=db.queryToList(sql);
65
66         return list;
67
68
69     }
70     

以上内容也是本人参考别人供源的代码作为参考写的,可能不是完全理解,但对比人的代码做了简化,去掉了dao层和model层。

附数据库内容:

下面是效果图:

时间: 2024-08-05 07:09:20

关于jui框架的java web分页刷新功能实现!的相关文章

MVC模式下基于SSH三大框架的java web项目excel表格的导出(不依赖另外的jar包)

最近工作中碰到了需要将web页面的表格内容导出到excel表格并下载到本地的需求.以下是在利用网上资源.与同事探讨下,完成的代码. 首先我们需要有定义好的实体类.以下是截取了项目中用到的部分代码. 1 public class QyggDocuments implements java.io.Serializable { 2 3 private static final long serialVersionUID = -2543382529255041149L; 4 5 private Stri

使用Struts框架的Java Web项目中的两个Session的区别和常见的Session取值为空的错误

我的百度知道回答,感觉这个知识很有意义,专门贴出来. 不过还有待验证的地方,就是 ActionContext.getContext().getSession("name", "Tom"); //如果在JSP中通过 EL 或者 Struts2 标签怎么显示? 以下是回答正文. 很多初学Java Web的同学因为使用 Strut2框架而分不清两个 Session的区别. 1.   JSP/Servlety有个原生的 session 对象,这是9大内置对象中的一个,书上写

第一个使用Struts框架的Java Web项目

今天早上第一次完成了一个HelloWorld级别的Java Web项目login(登陆验证)项目. 按照<JavaEE主流开源框架(第二版)>的指导做的. 1.先下载了struts:struts-2.3.16.3-all.zip,解压之后看到struts-2.3.16.3目录下有一个lib目录,这个目录里的全部是jar文件,采用struts框架需要使用jar包都在这个目录下. 2.根据书上的说明,先在myeclipse8.5中建立web project,命名为Login. 然后把下面的五个ja

java web 分页技术

查询界面,通过姓名和车号进行查询,然后将查询结果提交给servlet: <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.

java web 分页实现

   分页实现的效果:    ///////// /////////////////////////////////////////////////////// ////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////////////  ///////////////////////////////////////////

Java Web——分页技术

一.在数据库中存储的数据量特别大时(百万级以上),使用数据库分页技术,将已经分页好的数据存储在集合中返回给用户 1 /** 2 * 查询雇员(根据条件组合查询-数据库分页) 3 * @param emp 4 * @param pageSize 每页显示条数 5 * @param pageNum 当前页码 6 * @return 7 */ 8 public List<Emp> getEmp(Emp emp, int pageSize, int pageNum) { 9 try { 10 11 S

Java Web分页类分享

分页类分享: package com.hcj.util; import java.util.ArrayList; import java.util.List; import org.apache.struts2.json.annotations.JSON; //分页类 public class Page<E> { private int totals; //查询到的总数量 private List<E> bigList ; //总记录集 private List<E>

java web 程序---刷新页面次数

? 1 2 3 4 5 6 7 8 9 <%!        int count=0;             %>     <%     count++;        session.setAttribute("count",count);        out.print("您是第"+session.getAttribute("count")+"位访客");      %>

Java web图片验证功能实现二

上一篇实现的是最简单的图片验证,本文要实现复杂一点的:图片是旋转的,并通过一个注册实例把图片验证嵌套在网页中 实现图片旋转功能的代码为: //写字母 String content = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcedfghijklmnopqrstuvwxyz1234567890"; Random random = new Random(); Graphics2D graphics2D = (Graphics2D)graphics; //设置字体颜色 gr