æè¿ä¸ªæ¯åºäºsshå页çï¼åselevtå·®ä¸å¤ï¼ä½ å¯ä»¥åèä¸ä¸ï¼æéè¦çæ¯èªä¸ªä¼äºç解äºæè¡ï¼å«äººçæ»æ¯å«äººçããããããå¥½äº å¾ä¸çãå¼å§äºãããããããããããããããã å页åºè¯¥æ¯æ¯ä¸ªç¨åºåé½è¦ææ¡çææ¯ï¼ä¹æ¯ç¨å¤æå¤çä¸ç§ï¼æ¬äººä¸æï¼åäºä¸ä¸ªå页ï¼åºäºæ°æ®åºï¼ï¼è¯·å¤§å®¶æç¹ï¼é¦å
å¾æ¥ä¸ªå®ä½ç±»ï¼åå¨å页çä¿¡æ¯ï¼æèµ·å称å«Pageï¼
import java.util.ArrayList;
import java.util.List;public class Page {
private int totalPage = 1;/**
* åä¸é¡µ
*/
private int prePage = 1;/**
* ä¸ä¸é¡µ
*/
private int nextPage = 1;/**
* æ»è®°å½æ°
*/
private int totalRec = 0;/**
* é»è®¤æ¯é¡µè®°å½æ°
*/
private final int defaultPageSize = 10;/**
* æ¯é¡µè®°å½æ°
*/
private int pageSize = defaultPageSize;/**
* å½å页ç
*/
private int pageIndex = 1;/**
* å
¨é¨é¡µç ï¼ä»1å¼å§
*/
private int[] pageNumbers;public int getPageIndex() {
return pageIndex;
}public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex > 0 ? pageIndex : 1;
}public int getNextPage() {
return nextPage;
}public void setNextPage(int nextPage) {
this.nextPage = nextPage > this.totalPage ? this.totalPage : nextPage;
}public int getPageSize() {
return pageSize;
}public void setPageSize(int pageSize) {
this.pageSize = pageSize > 0 ? pageSize : 10;
}public int getPrePage() {
return prePage;
}public void setPrePage(int prePage) {
this.prePage = prePage < 1 ? 1 : prePage;
}public int getTotalPage() {
return totalPage;
}public void setTotalPage(int totalPage) {
this.totalPage = totalPage > 0 ? totalPage : 1;
}public int getTotalRec() {
return totalRec;
}public void setTotalRec(int totalRec) {
this.totalRec = totalRec > -1 ? totalRec : 0;
}public int[] getPageNumbers() {
return pageNumbers;
}public void setPageNumbers(int[] pageNumbers) {
this.pageNumbers = pageNumbers;
}
}
==============å®ä½ç±»æäºï¼æ们å¾å¨åä¸ä¸ªå
Œ
±çDAOæ¹æ³ï¼ä¹å°±æ¯æ¯ä¸ä¸ªç¨å°å页çå°æ¹é½ä¼è°ç¨è¿ä¸ªï¼================public List findPageByQuery(final String queryString,
final Object[] parameters, final Page pageInfo) {
return (List) getHibernateTemplate().execute(new HibernateCallback()//è¿é使ç¨äºå¿åå
é¨ç±»
{
public Object doInHibernate(Session session)//Springè¿è¡äºå¡ç»´æ¤ çå»æ¯æ¬¡å建sessionåå
³ésession
throws HibernateException
{
Query query = session.createQuery(queryString);
if (parameters != null)
{
for (int i = 0; i < parameters.length; i++)
{
query.setParameter(i, parameters[i]);
}
}
ScrollableResults sr = query.scroll();
sr.last();
int totalCount = sr.getRowNumber();
int startIndex = (pageInfo.getPageIndex() - 1)
* pageInfo.getPageSize();
query.setMaxResults(pageInfo.getPageSize());
query.setFirstResult(startIndex);
int totalRec = totalCount + 1;
pageInfo.setTotalRec(totalRec);
int totalPage = (totalRec % pageInfo.getPageSize() == 0) ? (totalRec / pageInfo
.getPageSize())
: (totalRec / pageInfo.getPageSize()) + 1;
int[] pageNumbers = new int[totalPage];
for (int i = 0; i < totalPage; i++)
{
pageNumbers[i] = (i + 1);
}
pageInfo.setPageNumbers(pageNumbers);
pageInfo.setTotalPage(totalPage);
pageInfo.setPageSize(pageInfo.getPageSize());
pageInfo.setPageIndex(pageInfo.getPageIndex());
pageInfo.setPrePage(pageInfo.getPageIndex() - 1);
pageInfo.setNextPage(pageInfo.getPageIndex() + 1);
return query.list();
}
}, true);
}
=================è³æ¤æ们çå·¥ä½å°±å®æäºä¸åäº ï¼æ¥ä¸äºå°±æ¹åå
·ä½çæ¹æ³äºï¼æ¥è°ç¨æ们çå
¬å·¥å页æ¹æ³public List getUU(int lexample,Page pageInfo)
{
/*ApplicationContext context = new ClassPathXmlApplicationContext(
"applicationContext.xml");
dao = (DaoImpl) context.getBean("Dao");
System.out.print(dao);*/ //èªå·±æµè¯æ¶åå¯ä»¥ä½¿ç¨
List list = null;
if (pageInfo == null)
pageInfo = new Page();
try
{
hql="SELECT exa FROM Example exa WHERE 1=1 AND exa.LExample="+lexample;
list = this.getCommonDAO().findPageByQuery(hql, null, pageInfo);
} catch (Exception ex)
{
System.out.println(ex);
}
return list;
}=============æ¥ä¸æ¥å°±æ¯actionä¸è°ç¨äº===============public ActionForward getMore(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ExampleForm exampleForm = (ExampleForm) form;// TODO Auto-generated method stub
List list = new ArrayList();
try
{
//pageInfo = (PageInfo) request.getAttribute("pageInfo");
String type=request.getParameter("type");
//ç±»å«ç¼å·
int typeId=0;
//页ç ç¼å·
String page=request.getParameter("page");
if(page==null)
{page="1";<br> }
if(type==null) {
//é»è®¤æ¾ç¤ºå¥³ç
type="2";
}
System.out.println("action...........................");
pageInfo.setPageIndex(Integer.parseInt(page));
pageInfo.setPageSize(20);
typeId=Integer.parseInt(type);
// pageInfo.setPageIndex(Integer.parseInt(request.getParameter("Index")));
list = this.exampleBiz.getUU(typeId,pageInfo);
if(list.size()!=0)
{
request.setAttribute("list", list);
request.setAttribute("pageInfo", pageInfo);
}
}catch
(Exception ex)
{
ex.printStackTrace();
}
return mapping.findForward("more");
}======ä¸é¢æ¯é¡µé¢ï¼æ们çå·¥ä½é©¬ä¸å°±å®äºã<%String nowPage ;
String type;
int total;
nowPage=request.getParameter("page");
if(nowPage==null)
{nowPage="1";<br>}
type=request.getParameter("type"); //è¿ä¸ªæ¯æ项ç®ä¸çç±»å«ï¼æ²¡å¿
è¦ç
if(type==null) {
type="2";
}
int curPage=Integer.parseInt(nowPage);
int typeId=Integer.parseInt(type);
System.out.println(typeId+"------------------------------------");
if((Page)request.getAttribute("pageInfo") == null){
total = 1;
} else {
total = ((Page)request.getAttribute("pageInfo")).getTotalPage();
if(curPage>((Page)request.getAttribute("pageInfo")).getTotalPage()) {
curPage=total;
}
}
%><div style="width:870px; margin-bottom:20px;">
<logic:notEmpty name="list">
<logic:iterate id="example" name="list">
<div class="s_ren">
<div><img src="example.account.headIcn" /></div>
<div class="style_ju"><strong>${example.account.name }</strong></div>
<div>ææææ°ï¼<span class="style_ju">254179</span></div>
<div style="float:left; background-color:#FFC189; text-align:center; height:22px; width:55px; line-height:22px;">éé²è±</div>
<div style="float:right; background-color:#9DCBE7; text-align:center;height:22px; width:55px; line-height:22px;">æ鸡è</div>
</div>
</logic:iterate>
</logic:notEmpty>
</div>
<div style=" border-top:1px solid #ccc; height:1px;"></div>
<div style="text-align:center">
<a href="${pageContext.request.contextPath }/example.do?method=getMore&page=1&type=<%=typeId %>">é¦é¡µ</a> |
<a href="${pageContext.request.contextPath }/example.do?method=getMore&page=<%=curPage-1<0?1:curPage-1%>&type=<%=typeId %>"">ä¸ä¸é¡µ</a> |
<a href="${pageContext.request.contextPath }/example.do?method=getMore&page=<%=(curPage+1)>total?total:curPage+1%>&type=<%=typeId %>"">ä¸ä¸é¡µ</a> |
<a href="${pageContext.request.contextPath }/example.do?method=getMore&page=<%=total %>">æ«é¡µ</a>
å½å第<%=curPage %>页 转å°ç¬¬ <select id="page" onchange="window.location.href='${pageContext.request.contextPath }/example.do?method=getMore&page='+document.getElementById('page').value;&type=<%=typeId %>"> <%
for(int toPage = 1; toPage<=total; toPage++) {
%>
<option value = <%=toPage%>
<%if(toPage==curPage){ %>
selected
<%} %>
>
<%=toPage %>
</option>
<%
}
%>
</select> 页
å
±<%=total%>页 ${pageInfo.pageIndex}
</div>OK!ï¼ç°å¨æ们çå页就è¡äºï¼èµ¶å¿«è¯è¯å§ï¼
温馨提示:内容为网友见解,仅供参考
jsp+servlet分页,点下一页,下一页的内容接上一页的内容显示,怎么办?
int lastStartRecord=0;\/\/最后一页开始显示记录的编号 public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { \/\/获取需要显示的页数,由用户提交 if(request.getParameter("pageNo")==null){ \/\/如果为空,则表示第1页 if(startRow == 0){...
在JSP中如何实现分页技术啊?
如果对RowSetPage.getHTML()生成的默认分页代码不满意可以编写自己的分页处理代码,RowSetPage提供了很多getter方法用于获取相关信息(如当前页码、总页数、 总记录数和当前记录数等)。 在实际应用中可以将分页查询和显示做成jsp taglib, 进一步简化JSP代码,屏蔽Java Code。 附:分页工具类的源代码, 有注释,应该很容易理...
jsp分页查询中 加入一段代码实现输入页码跳转
private void toList(HttpServletRequest request, HttpServletResponse response) { String key=request.getParameter("ukey");User u=new User();WebPage wp=new WebPage();u.setName(key);request.setAttribute("ukey", key);int currentPage=1;if(request.getParameter("currentPage")!=null){ ...
jsp怎么实现文章内容的分页显示,文章内容包含HTML标签。
1。取出的分页内容中,html标签不完整(比如<a href=,后面就没了。。。),针对这种情况,我们应该实现一个向前搜索和向后搜索内容以保证html标签完整性的功能。2。有可能出现标签不成对的情况,比如有,没有这种情况,那么这个问题也是我们需要去搜索内容来解决的。或者说做的过分点,我们写一个缺少结...
JSP+Servlet+JavaBean写“博奥教育网址之家“前台和后台,后台卡在分页...
给你一个通用的分页代码 但是数据量小的时候可以 大的时候就很慢了 pagesize \/\/每页显示的数据大小 rowcount\/\/行记录 iPage\/\/页数 pagecount\/\/总页数 recordcount \/\/总的记录数 sqlRst.last();recordcount = sqlRst.getRow();sqlRst.beforefirst();\/\/这段代码是取得总的记录数 然后进行分页...
JSP页面分页实现,大家帮忙啊
if (intPage > 1) { ><a href="<%=request.getContextPath()%>\/pages\/wish.jsp?page=<%=intPage - 1%>">上一页 < } > 祝愿人 接受人 祝愿内容 祝愿时间 < if (wishes.size() != 0) { for (Wish wish : wishes) { > <a href="<%=request.getContextPath(...
今天要写一个java分页的页面,jsp页面需要传三个参数beginpage 和 endp...
nowpage 默认是 request 作用范围的 在作为 servlet类里 应该 request.setRequest("nowpage",相应大变量);
java分页显示代码,在页面有每页显示的条数pageSize和当前页pageNow两个...
上一页,此处的a代表超链接,inut代表你的那个输入框,你最好给他们加上ID,然后代替掉他们
jsp怎么打开多个标签页
1、先定义一个实体类,包含一些设置信息和承载要显示的分页数据。2、然后开始编写分页标签。定义一个类,让它继承TagSupport类,然后重写其中的部分方法。3、通过在value属性来从Requst中获取之前从后台填充了数据的PageBean对象。标签类写完,还要编写对应的tlg文件。4、然后在web.xml中进行注册。5、再编写...
jsp页面如何让超链接无效,分页时如果是最后一页那么下一页就不可用
<%if(页码<总页数){ %> <a href="data_list_servlet?pageNo=<%=pageNo+1 %>">下一页 <%} %>意思就是如果当前页页码大于或者等于总页数的话,下一页这几个字就不显示了