小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

最簡(jiǎn)單的一個(gè)分頁思路

 昵稱22369024 2015-05-06

這個(gè)分頁思路適合于web中的各種分頁需要,不過只是最基本的

package com.netshop.tag;

import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.netshop.data.*;

public class shownews extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
public int i=0;
@Override
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
JspWriter out=pageContext.getOut();
HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
DataStore ds=DataStore.getInstance();
ResultSet rs=null;
String sql_count="select count(*) from news";
String sql="select * from news";
String tmp=null;
int count=0;//記錄總數(shù)
int page=0; //當(dāng)前要顯示的頁數(shù)
int total_page=0;//頁面總數(shù)
try{
count=ds.readCount(sql_count);
}
catch(Exception ex)
{
count=0;
}
total_page=count/6;//計(jì)算總頁面
try
{
rs=ds.read(sql); //讀取所有的記錄集
}
catch(Exception e)
{
rs=null;
}
try
{
tmp=(String)request.getParameter("page");//從request中讀取page參數(shù)
if(tmp==null)
page=0;
else
page=Integer.parseInt(tmp);
}
catch(Exception ex1)
{
page=0;
}

//輸出記錄
try
{
out.print("<table width=600 height=30 border=1 cellpadding=0 bordercolor=#0066FF>");
out.print("<tr align=center><td height=30>編號(hào)</td><td height=30>標(biāo)題</td><td height=30>刪除</td></tr>");
//重點(diǎn)
for(i=0;i<page*6;i++)
{
rs.next();
}
i=page*6;
int j=0;
while((rs!=null)&&(rs.next())&&(j<6))
{
String newsid=rs.getString(1);
String newstitle=rs.getString(2);
newstitle=new String(newstitle.getBytes("ISO-8859-1"),"UTF-8");
out.print("<tr align=center><td height=30>"+newsid+"</td>");
out.print("<td height=30>"+newstitle+"</td>");
out.print("<td height=30><a href=deletenews.jsp?id="+newsid+">刪除</a></td></tr>");
j++;
}
if(page>0)
{
out.print("<tr align=center><td height=30 colspan=3><a href=news_edit.jsp?page=0>首頁</a>");
out.print("<a href=news_edit.jsp?page="+(page-1)+">上一頁</a>");
}
else
{
out.print("<tr align=center><td height=30 colspan=3>首頁");
out.print("上一頁");
}
if(page<total_page)
{
out.print("<a href=news_edit.jsp?page="+(page+1)+">下一頁</a>");
out.print("<a href=news_edit.jsp?page="+total_page+">末頁</a></td></tr>");
}
else
{
out.print("下一頁");
out.print("末頁</td></tr>");
}
out.print("</table>");
}
catch(Exception e)
{

}
return super.doEndTag();
}
}


    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多