日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

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

 昵稱22369024 2015-05-06

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

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)前要顯示的頁(yè)數(shù)
int total_page=0;//頁(yè)面總數(shù)
try{
count=ds.readCount(sql_count);
}
catch(Exception ex)
{
count=0;
}
total_page=count/6;//計(jì)算總頁(yè)面
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>首頁(yè)</a>");
out.print("<a href=news_edit.jsp?page="+(page-1)+">上一頁(yè)</a>");
}
else
{
out.print("<tr align=center><td height=30 colspan=3>首頁(yè)");
out.print("上一頁(yè)");
}
if(page<total_page)
{
out.print("<a href=news_edit.jsp?page="+(page+1)+">下一頁(yè)</a>");
out.print("<a href=news_edit.jsp?page="+total_page+">末頁(yè)</a></td></tr>");
}
else
{
out.print("下一頁(yè)");
out.print("末頁(yè)</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)購(gòu)買(mǎi)等信息,謹(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)論公約

    類(lèi)似文章 更多