JSP中如何将查询数据库返回的数据分页显示在页面中
本回答由提问者推荐&/c:choose&&!- - 页数列表 --&&c:forEach items=&${pageList}& var=&item&&&c:choose&&c:when test=&${item == page}&&&a href=&checkComments.do?page=${item}& class=¤tPage&&${item}&/a&&/c:when&&c:otherwise&&a href=&checkComments.do?page=${item}&&${item}&/a&&/c:otherwise&&/c:choose&&/c:forEach&&!- - 下一页 按钮 --&&c:choose&&c:when test=&${page != totalPages}&&&a href=&checkComments.do?page=${page+1}&&&in put type=&button& name=&nextPage& value=&下一页& /&&/a&&/c:when&&c:otherwise&&in put type=&button& disabled=true name=&nextPage& value=&下一页& /&&!- - 为了要那个灰掉的button --&&/c:otherwise&&/c:choose&&!- - 直接跳转 --&共${totalPages}页 -向&in put type=&text& id=&jumpTo& /&页 &in put type=&button& value=&跳转& on click=&jumpTo(${totalPages})& /&&/div&使用到的js函数function jumpTo(maxPage){var page = $(&#jumpTo&).val();if(page & maxPage || page & 1){alert(&对不起,无法到达该页&)}else{$('body').load('checkComments.do?page=' + page);}}6、CSS增强效果为了凸显我们现在所在的页数,在上面的代码中我们特意做了判断:&c:when test=&${item == page}&&&a href=&checkComments.do?page=${item}& class=¤tPage&&${item}&/a&&/c:when&这样,当前的页数就会被标记为currentPage类,如此一来,就可以在CSS文件中着重强调它了。比如:.currentPage{font-weight:color:#ff9a00;}或者再设置以下跳转页输入框的宽度#jumpTo{width:20}这样,当前页的页面就会被标记为粗体、橘色:7、改进用a标签的方法做链接虽然比较方便,不过会有下划线出现,感觉很不洋气。可以用css把它消除掉,或者hover时候加一些变化什么的。#pageControl a {text-decoration:}免责声明:本文仅代表作者个人观点,与本网无关。看完本文,记得打分哦:很好下载Doc格式文档马上分享给朋友:?知道苹果代表什么吗实用文章,深受网友追捧比较有用,值得网友借鉴没有价值,写作仍需努力相关综合教程:
48小时热门本帖子已过去太久远了,不再提供回复功能。博客访问: 1528135
博文数量: 456
博客积分: 10010
博客等级: 上将
技术积分: 3272
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: Java
//接口的定义: public interface ContactBean { public int getAvailableCountthrows E public int getAvailableCountint idthrows E public PageBean listDataString pagethrows E public PageBean listDataString page,int idthrows E public Collection getResultthrows E } //pageBean的定义: public class PageBean { public int curP//当前的页值。 public int maxP//最大的页数。 public int maxRowC//最大的行数。 public static int rowsPerPage=10; //控制分页的行数。 public java.util.C //所要显示的数据的集合。 public PageBean { } public void countMaxPage{ ifthis.maxRowCount%this.rowsPerPage==0{ this.maxPage=this.maxRowCount/this.rowsPerP }else{ this.maxPage=this.maxRowCount/this.rowsPerPage+1; } } public Collection getResult{ return this. } public PageBeanContactAdapter bean,int idthrows Exception{ this.maxRowCount=bean.getAvailableC ifmaxRowCount==0 maxRowCount=1; System.out.printlnmaxRowC this.data=bean.getR this.countMaxP } public PageBeanContactAdapter beanthrows Exception{ this.maxRowCount=bean.getAvailableC this.data=bean.getR this.countMaxP } } //对ContactBean接口进行adapter模式的封装。方便实用。 public class ContactAdapter implements ContactBean{ public ContactAdapter { } public int getAvailableCountthrows Exception{ return 0; } public int getAvailableCountint idthrows Exception{ return 0; } public PageBean listDataString pagethrows Exception { } public PageBean listDataString page,int idthrows Exception { } public Collection getResultthrows Exception{ } } 在使用中你可以实现.interfaces.ContactBean 或继承 .interfaces.ContactAdapter都可以。 实现方法: 实现一:其中不需要键入任何参数。 public int getAvailableCountthrows E public PageBean listDataString pagethrows E public Collection getResultthrows E 实现二:需要键入参数。 public int getAvailableCountint idthrows E public PageBean listDataString page,int idthrows E public Collection getResultthrows E 例如: Public class TestContact extends ContactAdapter{ Private C Public int getAvailableCountint unitID throws Exception{ BSIResultSet rs = new DBUtil.getResult“ select count NUM from TableTest where unit_id ="+ return rs.getIntNUM; } public PageBean listDataString page,int incept_sort_idthrows Exception { PageBean p = new PageBeanthis,incept_sort_ int pageNum = Integer.parseI BSIResultSet rs = con.getResult sql, pageNum -1 p.rowsPerPage,, pageNump.rowsPerPage ; p.curPage = pageN p.data = this.getTestB //此方法是把查询的数据封装在一个collection中。 } public Collection getResultthrows Exception{ return this. } } 其中testBean是封装好的数据bean。 如果没有参数的话。可以使用没有参数的一组接口。 例如:在jsp中如何是用借口。 &jsp:useBean id="pageCtl" class=".page.PageBean" scope="request"/& &% Vector c=VectorpageCtl.getR Iterator it=c. whileit.hasNext{ TestBean d=TestBeanit.//的到每一个单独的数据。 //可以取出此bean的属性值。 %& 。。。。。//属性使用。业务逻辑。 &form action="test.do" method="post" name="PageForm"& &%out.printViewPage.getViewpageC%& &/form& //显示分页的表单。 加入javaScript的page.js.在jsp页面上加入: &script language="JavaScript" src="js/page.js"&即可。 function jumping{ document.PageForm. } function gotoPagePagenum{ document.PageForm.jumpPage.value=P document.PageForm.
阅读(1659) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。}