- 浏览: 95686 次
- 性别:
- 来自: 北京
最新评论
-
OHdream:
OHdream 写道"因为该文件已经包含了lombo ...
jsp开发所需要的eclipse插件(lomboz、tomcatplugin)及其安装、配置方法 -
OHdream:
"因为该文件已经包含了lomboz和emf,并且该插 ...
jsp开发所需要的eclipse插件(lomboz、tomcatplugin)及其安装、配置方法 -
maxer025:
Mark hehe
lomboz插件 -
Jasper_Success:
谢谢!受用!
struts2 标签 输出时间格式 -
bo_hai:
哎!没有创新呀!
【转帖】Java项目开发规范
Java代码
- package com.pms.util;
- import java.util.List;
- /**
- * Pagination.java
- * utils class
- * @author fanfq 2009-6-7
- *
- * */
- public class Pagination<T> { //这里我使用的范型
- private int currentPage = 1 ; // 当前页数
- private int pageCount = 20 ; // 每页数据的条数
- private int pageSize; // 总页数
- private int valueCount; // 总数据的条数
- private List<T> pageList; // 分页集合
- private int previousPageCount; // 上一页的页数
- private int nextPagecount; // 下一页的页数
- public void setCurrentPage( int currentPage) {
- this .currentPage = currentPage;
- // 上一页
- previousPageCount = currentPage - 1 ;
- // 下一页
- nextPagecount = currentPage + 1 ;
- }
- public void setPageList(List<T> pageList) {
- this .pageList = pageList;
- pageSize = valueCount % pageCount == 0 ? valueCount / pageCount
- : valueCount / pageCount + 1 ;
- }
- public int getCurrentPage() {
- return currentPage;
- }
- public int getPageCount() {
- return pageCount;
- }
- public void setPageCount( int pageCount) {
- this .pageCount = pageCount;
- }
- public int getPageSize() {
- return pageSize;
- }
- public void setPageSize( int pageSize) {
- this .pageSize = pageSize;
- }
- public int getValueCount() {
- return valueCount;
- }
- public void setValueCount( int valueCount) {
- this .valueCount = valueCount;
- }
- public List<T> getPageList() {
- return pageList;
- }
- public int getPreviousPageCount() {
- return previousPageCount;
- }
- public void setPreviousPageCount( int previousPageCount) {
- this .previousPageCount = previousPageCount;
- }
- public int getNextPagecount() {
- return nextPagecount;
- }
- public void setNextPagecount( int nextPagecount) {
- this .nextPagecount = nextPagecount;
- }
- }
package com.pms.util; import java.util.List; /** * Pagination.java * utils class * @author fanfq 2009-6-7 * * */ public class Pagination<T> {//这里我使用的范型 private int currentPage = 1; // 当前页数 private int pageCount = 20; // 每页数据的条数 private int pageSize; // 总页数 private int valueCount; // 总数据的条数 private List<T> pageList;// 分页集合 private int previousPageCount;// 上一页的页数 private int nextPagecount; // 下一页的页数 public void setCurrentPage(int currentPage) { this.currentPage = currentPage; // 上一页 previousPageCount = currentPage - 1; // 下一页 nextPagecount = currentPage + 1; } public void setPageList(List<T> pageList) { this.pageList = pageList; pageSize = valueCount % pageCount == 0 ? valueCount / pageCount : valueCount / pageCount + 1; } public int getCurrentPage() { return currentPage; } public int getPageCount() { return pageCount; } public void setPageCount(int pageCount) { this.pageCount = pageCount; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getValueCount() { return valueCount; } public void setValueCount(int valueCount) { this.valueCount = valueCount; } public List<T> getPageList() { return pageList; } public int getPreviousPageCount() { return previousPageCount; } public void setPreviousPageCount(int previousPageCount) { this.previousPageCount = previousPageCount; } public int getNextPagecount() { return nextPagecount; } public void setNextPagecount(int nextPagecount) { this.nextPagecount = nextPagecount; } }
Java代码
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doPost(request, response);
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- //分页查询操作
- String currentpage = request.getParameter("pageindex" );
- if (currentpage == null ){
- currentpage = "1" ;
- }
- int pageindex = Integer.parseInt(currentpage);
- Pagination<Dept> pc = new Pagination<Dept>(); //这里我使用的范型
- int count = pc.getPageCount();
- int cursor = count * (pageindex- 1 );
- pc.setValueCount(new DeptDao().getDeptCount());
- List<Dept> allList = new DeptDao().getAllDeptByPagenation(cursor,count); //关键之处定位查询
- pc.setValueCount(new DeptDao().getDeptCount());
- pc.setPageList(allList);
- pc.setCurrentPage(pageindex);
- request.setAttribute("pc" , pc);
- this .getServletContext().getRequestDispatcher( "/page/xx_list.jsp" ).forward(request, response);
- }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //分页查询操作 String currentpage = request.getParameter("pageindex"); if(currentpage == null){ currentpage = "1"; } int pageindex = Integer.parseInt(currentpage); Pagination<Dept> pc = new Pagination<Dept>(); //这里我使用的范型 int count = pc.getPageCount(); int cursor = count * (pageindex-1); pc.setValueCount(new DeptDao().getDeptCount()); List<Dept> allList = new DeptDao().getAllDeptByPagenation(cursor,count);//关键之处定位查询 pc.setValueCount(new DeptDao().getDeptCount()); pc.setPageList(allList); pc.setCurrentPage(pageindex); request.setAttribute("pc", pc); this.getServletContext().getRequestDispatcher("/page/xx_list.jsp").forward(request, response); }
Java代码
- /**定位查询*/
- public List<Dept> getAllDeptByPagenation( int cursor, int rows) {
- String sql = "SELECT * FROM dept limit " + cursor + "," + rows;
- ResultSet rs = DBPool.exeQuery(sql);
- List<Dept> list = new ArrayList<Dept>();
- try {
- while (rs.next()) {
- Dept fDept = new Dept();
- fDept.setDeptid(rs.getInt(1 ));
- fDept.setDeptname(rs.getString(2 ));
- fDept.setDeptbesc(rs.getString(3 ));
- fDept.setDeptmanager(rs.getInt(4 ));
- list.add(fDept);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- DBPool.closeConnection();
- return list;
- }
- /**获得部门数*/
- public int getDeptCount(){
- String sql = "select count(*) from dept" ;
- ResultSet rs = DBPool.exeQuery(sql);
- int count = 0 ;
- try {
- if (rs.next()){
- count = rs.getInt(1 );
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- DBPool.closeConnection();
- return count;
- }
/**定位查询*/ public List<Dept> getAllDeptByPagenation(int cursor,int rows) { String sql = "SELECT * FROM dept limit " + cursor + "," + rows; ResultSet rs = DBPool.exeQuery(sql); List<Dept> list = new ArrayList<Dept>(); try { while (rs.next()) { Dept fDept = new Dept(); fDept.setDeptid(rs.getInt(1)); fDept.setDeptname(rs.getString(2)); fDept.setDeptbesc(rs.getString(3)); fDept.setDeptmanager(rs.getInt(4)); list.add(fDept); } } catch (SQLException e) { e.printStackTrace(); } DBPool.closeConnection(); return list; } /**获得部门数*/ public int getDeptCount(){ String sql = "select count(*) from dept"; ResultSet rs = DBPool.exeQuery(sql); int count = 0 ; try { if(rs.next()){ count = rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } DBPool.closeConnection(); return count; }
Html代码
- < %@ page language = "java" import = "java.util.*" pageEncoding = "UTF-8" % >
- < %@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" % >
- < body >
- < div class = "title" >
- < h1 > 所有部门信息 </ h1 >
- < table > < tr > < td >
- 相关操作:
- </ td > </ tr > </ table >
- </ div >
- < table >
- < thead >
- < th width = "10%" > 部门编号 </ th >
- < th width = "20%" > 部门名称 </ th >
- < th width = "20%" > 部门概述 </ th >
- < th width = "20%" > 部门经理 </ th >
- < th width = "10%" > 操作 </ th >
- </ thead >
- < c:forEach var = "pc" items = "${pc.pageList}" >
- < tr class = "a1" align = "center" onmousemove = "color=this.style.backgroundColor;this.style.backgroundColor='rgb(214,229,249)'" style = "width: 529px" onmouseout = "this.style.backgroundColor='white'" >
- < td > ${pc.deptid} </ td >
- < td > ${pc.deptname} </ td >
- < td > ${pc.deptbesc} </ td >
- < td > < a href = "#" target = "" > ${pc.deptmanager} </ a > </ td >
- < td > < a target = "" onClick = "Myopen(User,${pc.deptid})" > 修改 </ a > </ td >
- </ tr >
- </ c:forEach >
- </ table >
- < div class = "title" >
- < table > < tr align = "right" > < td >
- 第${pc.currentPage}/${pc.pageSize}页
- < a href = "DeptServlet?pageindex=1" > 首页 </ a >
- < c:if test = "${pc.previousPageCount > 0}" var = "true" >
- < a href = "DeptServlet?pageindex=${pc.previousPageCount}" > 上一页 </ a >
- </ c:if >
- < c:if test = "${pc.nextPagecount <= pc.pageSize}" var = "true" >
- < a href = "DeptServlet?pageindex=${pc.nextPagecount}" > 下一页 </ a >
- </ c:if >
- < a href = "DeptServlet?pageindex=${pc.pageSize}" > 尾页 </ a >
- </ td > </ tr > </ table >
- < h1 > **fanfq.iteye.com** </ h1 >
- </ div >
- </ body >
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <body> <div class="title"> <h1>所有部门信息</h1> <table><tr><td> 相关操作: </td></tr></table> </div> <table> <thead> <th width="10%">部门编号</th> <th width="20%">部门名称</th> <th width="20%">部门概述</th> <th width="20%">部门经理</th> <th width="10%">操作</th> </thead> <c:forEach var="pc" items="${pc.pageList}"> <tr class="a1" align="center" onmousemove="color=this.style.backgroundColor;this.style.backgroundColor='rgb(214,229,249)'" style="width: 529px" onmouseout="this.style.backgroundColor='white'"> <td>${pc.deptid}</td> <td>${pc.deptname}</td> <td>${pc.deptbesc}</td> <td><a href="#" target="">${pc.deptmanager}</a></td> <td><a target="" onClick="Myopen(User,${pc.deptid})">修改</a></td> </tr> </c:forEach> </table> <div class="title"> <table><tr align="right"><td> 第${pc.currentPage}/${pc.pageSize}页 <a href="DeptServlet?pageindex=1">首页</a> <c:if test="${pc.previousPageCount > 0}" var="true"> <a href="DeptServlet?pageindex=${pc.previousPageCount}">上一页</a> </c:if> <c:if test="${pc.nextPagecount <= pc.pageSize}" var="true"> <a href="DeptServlet?pageindex=${pc.nextPagecount}">下一页</a> </c:if> <a href="DeptServlet?pageindex=${pc.pageSize}">尾页</a> </td></tr></table> <h1>**fanfq.iteye.com**</h1> </div> </body>
发表评论
-
如何在Struts2中实现Web系统的初始化工作
2014-03-15 15:07 610通常web系统在启动时需要做一些初始化的工作,比如初始化系统 ... -
Java中带包的类的编译与执行 .
2014-02-26 18:02 766Java 中带包的类的编译与执行 以HelloWorld ... -
InnoDB和MyISAM区别总结
2013-07-02 15:34 604InnoDB和MyISAM是许多人在使用MySQL时最常用的 ... -
搞懂java中的synchronized关键字
2012-11-22 14:20 648实际上,我关于java的基础知识的90%以上都来自Thinki ... -
Eclipse code template
2012-04-17 10:29 1555设置注释模板的入口: Window->Preferenc ... -
全面解析Java中的String数据类型
2012-02-12 12:29 7401. 首先String不属于8种基本数据类型,String是一 ... -
JAVA任务调度实现方法一
2011-08-14 15:49 942背景:目前因工作需要,要实现WEB项目设计动态加载XML文件的 ... -
Iframe高度自适应(兼容IE/Firefox、同域/跨域)
2011-06-17 16:11 838Iframe高度自适应(兼容IE/Firefox、同域/跨域 ... -
Struts 2中实现文件下载(修正中文问题)
2011-05-05 13:53 831在BlogJava上已经有一位作者阐述了文件上传的问题,地址是 ... -
JPA的merge和persist !
2011-03-18 18:22 1403原来merge()也有persist()的 ... -
jquery选择器
2011-03-16 14:28 761JQuery选择器 $的选择器部分: 凡是运 ... -
js父页面操作的父子页面传值
2011-03-09 11:58 1657对iframe来说,父页面访问 ... -
Ajax动态加载目录树(jquery-treeview)
2011-03-04 14:08 3685需求: 动态加载目录树节点数据。即 ... -
struts2 标签的使用之二 s:iterator
2011-03-03 16:08 1172struts2的s:iterator 可以遍历 数据栈里面的任 ... -
struts2 标签 输出时间格式
2011-02-25 10:14 1181使用<s:date>标签,有一个format属性, ... -
JPA 的一些详细说明
2011-02-25 10:12 1046@Temporal(TemporalType.DATE):如果 ... -
struts2 分页
2011-02-22 15:07 900首先写了一个分页的类,其实只有主要属性的setter和gett ... -
关于JPA中使用原生SQL语句
2011-02-21 10:36 4579import org.springframework.con ... -
ORACLE自动断开数据库连接解决办法
2011-02-14 16:56 2226ORACLE自动断开数据 ... -
oracle导入导出数据和导出表结构
2011-01-27 15:57 1763导出一个用户下的所有表数据 常用的命令 Exp ...
相关推荐
基于javascript真分页+servlet 内有文档说明
Gridview数据真分页,包含存储过程、前台绑定、后台操作说明
使用AspNetPager控件,进行简单的 分页。里面包含 真假分页的对比。当然,仅仅是一个例子而已,就没有美化了。
使用数据库特定SQL语句和存储过程真分页,用存储方式实现真分页,可以直接用的。
Oracle真分页。源码 帮做毕业设计。使用JAVA底层编码、四大框架。 帮做毕业设计。使用JAVA底层编码、四大框架。 帮做毕业设计。使用JAVA底层编码、四大框架。
这是自己研发的用户控件,功能很强大,能对各种控件进行分页。ASP.NET超强的存储过程万能真分页,这是一个调用存储过程的很强悍的真分页。对ASP.NET的同学很有帮助的
jsp servlet 实现的真分页与假分页,jsp servlet 实现的真分页与假分页
1.真正分页, 只取需要的数据; 2.无刷新; 3.高效简洁; 4.基于jquery和.net(vs2008),适合GridView,Repeater等一切数据控件;(有时间再做一个java版的, 当然, 其实思路是一样的, java的同志也可以下载了研究一下, 不难的...
JSP+JDBC_真分页(基于Oracle数据库分页)笔记JSP+JDBC_真分页(基于Oracle数据库分页)笔记JSP+JDBC_真分页(基于Oracle数据库分页)笔记
.NET实现真分页自定义控件支持Sqlserver2005和Oracle版本,在代码中与以往分页控件不一样,我们现在只需一行代码就实现分页,且是真分页,在数据库分页的。配合控件使用的SQL脚本我已经上传,速度还是不错的。主要是...
易语言记录集真分页显示源码,记录集真分页显示,读取数据
易语言源码易语言记录集真分页显示源码.rar 易语言源码易语言记录集真分页显示源码.rar 易语言源码易语言记录集真分页显示源码.rar 易语言源码易语言记录集真分页显示源码.rar 易语言源码易语言记录集真分页显示...
这是两个可以直接执行的代码,下载后在myeclipse下通过新建Jsp文件即已使用...
用JSP实现的真分页和假分页,环境 Tomcat+mysql
JSP真分页技术
本案例使用ajax技术实现分页,方案为其中一种,其他方案后面会再发,因为项目比较有针对性,所以项目规模很小,便于查看学习,使用前先修改项目中的Constant类中的相关静态变量信息(数据库连接信息)后便可部署。...
.net 分页代码,实现真分页。很不错的资源。不再使用传统的假分页,使用真分页提高系统性能
JSP+JDBC_真分页(基于Oracle数据库分页).
NULL 博文链接:https://shanke0101-163-com.iteye.com/blog/1201220
1.真正分页, 只取需要的数据; 2.无刷新; 3.高效简洁; 4.基于jquery和.net(vs2008),适合GridView,Repeater等一切数据控件;(有时间再做一个java版的, 当然, 其实思路是一样的, java的同志也可以下载了研究一下, 不难的...