高分相送,问题很简单的!!

asp_badboy 2003-04-08 01:21:58
谁能不能MAIL一个JSP数据分页的完整代码给我啊!
谢了!!
...全文
15 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
IT老兵 2003-06-13
http://www-900.ibm.com/developerWorks/cn/java/l-jspdisp/index.shtml
回复
Tomcat4 2003-04-19
给你一段代码。
xuefeng.database.dbConn 数据库连接类
xuefeng.database.page mp 分页用的类

String strPage="",table;
int intPage = 0 ;
strPage= request.getParameter("p");
if(request.getParameter("table")==null)
table = "lt_zkzx";
else
table = request.getParameter("table");
if(strPage==null) //表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
else
{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}

xuefeng.database.dbConn db = new xuefeng.database.dbConn() ;
xuefeng.database.page mp = new xuefeng.database.page(15) ;
Statement st = null ;
ResultSet rs = null ;
String title,author,fbtime,level,sql ;
String[] color={"#e2f3ff","#FDF0EA"};
int id,i=0,reply=0,p_id=0 ;
st = db.getStatement(true);
Statement st2 = db.getStatement(false);
sql = "select * from "+table+" where p_id=0 order by mdtime desc";
rs = st.executeQuery(sql);
if(rs.next())
{
rs.last();
mp.rowCount = rs.getRow();
mp.pageCount = (mp.rowCount+mp.pageSize-1)/mp.pageSize;

//调整待显示的页码
if(intPage>mp.pageCount) intPage = mp.pageCount;
if(mp.pageCount>0)
{
//将记录指针定位到待显示页的第一条记录上
rs.absolute((intPage-1) * mp.pageSize+1);
//显示数据
i = 0;
if (mp.rowCount-(intPage-1)*mp.pageSize<mp.pageSize)
mp.pageSize=mp.rowCount-(intPage-1)*mp.pageSize;
else
mp.pageSize=mp.pageSize;
}

out.println("<table align=center width=550 cellspacing=1 cellpadding=1>");
out.println("<tr valign=bottom><td><a href=fayan.jsp?table="+table+">新话题</td>");
%>
<td><SCRIPT>
var s = parent.left.document.lt_sel.myform.table.options[parent.left.document.lt_sel.myform.table.selectedIndex].value
var admin = parent.left.lt_sel.document.all(s).value
document.write("版主:<font color=red>"+admin+"</font>")
</SCRIPT></td>
<%
out.print("<td align=right>");
out.println("第<font color=red>"+intPage+"</font>页/共<font color=red>"+mp.pageCount+"</font>页 ");
if(intPage==1)
out.println("首页");
else
out.println("<a href=title.jsp?p="+1+"&table="+table+">首页</a>");
for(i=1;i<=mp.pageCount;i++)
{
if(i>8)
{
out.println("..");
break;
}
if(i==intPage)
out.println(i);
else
out.println("<a href=title.jsp?p="+i+"&table="+table+">"+i+"</a>");
}
if(intPage==mp.pageCount)
out.println("尾页");
else
out.println("<a href=title.jsp?p="+mp.pageCount+"&table="+table+">尾页</a>");
out.println("转到:<input type=text name='goto' size=3>");
//out.println("<input type=button value=' Go ' onclick='goto()'>");
out.println("<IMG class=pic SRC='/images/go.gif' height=18 width=28 onclick='goto()' />");
i=0 ;
out.println("</td></tr></table>");
out.println("<table align=center width=550 cellspacing=1 cellpadding=1>");
out.println("<tr bgcolor=#B0A2C4>");
out.println("<td width=310 align=center><b><font color=white>标题</font></b></td>");
out.println("<td width=30 align=center><b><font color=white>回复</font></b></td>");
out.println("<td width=80 align=center><b><font color=white>作者</font></b></td>");
out.println("<td width=130 align=center><b><font color=white>最后更新时间</font></b></td>");
//while(rs.next())
while(i<mp.pageSize && !rs.isAfterLast()&& rs.getString("id")!=null)
{
id = rs.getInt("id");
p_id = rs.getInt("p_id");
level = rs.getString("authorlevel").trim();
reply = rs.getInt("reply");
title = rs.getString("title");
author = rs.getString("author");
//level = rs.getString("author");
//out.println(level);//.equals("3"));
if(!level.equals("3")&&!level.equals("4"))
title = "<font color=red>"+title+"</font>";
fbtime = rs.getDate("mdtime").toString()+" "+rs.getTime("mdtime").toString();
out.println("<tr bgcolor="+color[i%2]+"><td><a href='content.jsp?id="+id+"&table="+table+"'> "+title+"</a></td><td align=center>"+reply+"</td>");
out.println("<td align=center>"+author+"</td><td align=center>"+fbtime+"</td></tr>");
rs.next();
i++;
}
out.println("<input type=hidden name=hTable value='"+table+"'>");
out.println("</table>");
rs.close();
st.close();
db.close();
}
回复
网络咖啡 2003-04-13
up
回复
harness 2003-04-11
好~~~~~~~ up~~~~~~~~~
回复
lynx800602 2003-04-10
<html>
<head>
<%@ page contentType="text/html;charset=gb2312" %>
<title>会员管理</title>
<link rel=stylesheet href="../style.css" type="text/css">
<script LANGUAGE="javascript">
function newwin(url) {
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
newwin.focus();
return false;
}
</script>
</head>
<body>
<script LANGUAGE="javascript">
function submit10()
{
self.location.replace("admin_user.jsp")
}
</script>
<jsp:include page="../top.jsp" flush="true"/>
<center><p><h4><font color="blue">会员管理</font></h4></p>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="adminBean" scope="page" class="firm.firm" />
<%
//指定行数
int pageLine=10;
int totalRec=0;
int totalSub=0;
int intPage=1;
int i;
if (request.getParameter("page")!=null)
intPage=Integer.parseInt(request.getParameter("page"));

try{
ResultSet countrs=null;

//取得总记录数
countrs=adminBean.executeQuery("select count(*) as cnt from user where name<>'administrator'");
if (countrs.next())
totalRec=countrs.getInt("cnt");
countrs.close();
adminBean.closeStmt();

}
catch(Exception e){
e.printStackTrace();
}

//取得总页数
int intPageCount=0;
intPageCount = (totalRec+pageLine-1) / pageLine;
%>
<%
ResultSet RS = adminBean.executeQuery("SELECT * FROM user where name<>'administrator' order by id desc");
String name;
String userid;

%>
<table border='1' cellspacing='0' width='500' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>
<tr bgcolor='#c8cc98' align='center'>
<td width='8%'>ID</td>
<td width='14%'>会员名</td>
<td width='8%' >删除</td>
</tr>
<%
if (intPageCount>0)
{
for(i=1;i<=(intPage-1)*pageLine;i++)
RS.next();
for(i=1;i<=pageLine;i++) {
if (RS.next()) {

name=RS.getString("name");
userid=RS.getString("id");
%>
<tr>
<td width='8%' align='center'><%=userid%></td>
<td width='14%' align='center'><%=name%></td>
<td width='8%' align='center'><a href="delete.jsp?id=<%=userid%>" onClick="return newwin(this.href);">删除</a></td>
</tr>
<%
}
}
RS.close();
}
%>
<!--以下用于分页显示 -->
<%
out.print("<tr>");
if (intPageCount*pageLine<totalRec)
intPageCount++;
if (intPage>intPageCount )
intPage=intPageCount;
if (intPage < 1 )
intPage=1;
out.print("<form method='POST' name=fPageNum action='admin_user.jsp'>");
out.print("<p align='left'>>>分页 ");

if (intPage<2)
out.print("<font color='999966'>首页 上一页</font> ");
else{
out.print("<a href='admin_user.jsp?page=1'>首页</a> ");
out.print("<a href='admin_user.jsp?page=" + (intPage-1) + "'>上一页</a> " );
}


if( intPage-intPageCount>=0 )
out.print("<font color='999966'>下一页 尾页</font>" );
else{

out.print("<a href='admin_user.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='admin_user.jsp?page=" + intPageCount + "'>尾页</a>");
}

out.print(" 页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 " );
out.print(" 共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 " );
out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");
out.print("页<input class=buttonface type='submit' value='GO' name='cndok'></span></p></form>" );

out.print("</td>");
out.print("</tr>");

%>
</table></p>
<a href="javascript:window.close();">[关闭]</a>
</center>
<jsp:include page="../bottom.jsp" flush="true"/>
</body>
</html>
回复
asp_badboy 2003-04-10
继续啊!!
先谢谢各位了!!
回复
foolbirds 2003-04-08
http://www-900.ibm.com/developerWorks/cn/java/l-jspdisp/index.shtml
回复
wyvc 2003-04-08
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*" %>

<html>
<body>
开始时间:<%=(new java.util.Date() ).toLocaleString()%><br>
<%
int page_record=100,Cpage,CurrentPage;
String Spage=request.getParameter("Cpage"),SCurrentPage=request.getParameter("CurrentPage");
if (Spage!=null)
{ Cpage=Integer.parseInt(Spage) ;}
else
{ Cpage=1; }
if (SCurrentPage!=null)
{CurrentPage=Integer.parseInt(SCurrentPage) ;}
else
{CurrentPage=1 ;}

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:timesinfo","sa","sa");

Statement stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

String sql="select top 100 * from timesinfonews where id not in( select top "+CurrentPage*page_record+" id from timesinfonews order by id desc) order by id desc";
ResultSet rs=stat.executeQuery(sql);
while(rs.next())
{%>
标题: <%=rs.getString("title").substring(0,5)%>... <br>

<%
}
out.println("数据库操作成功,恭喜你");
rs.close();
stat.close();
conn.close();

%>
<%//此处需要对页数进行判断,是否到达最后一页和第一业%>
<a href=datebase.jsp?Cpage=<%=Cpage-1%>¤tPage=<%=Cpage%>>上一页</a>
<a href=datebase.jsp?Cpage=<%=Cpage+1%>¤tPage=<%=Cpage%>>下一页</a>

结束时间:<%=(new java.util.Date() ).toLocaleString()%>
</body>
回复
FrogKiller 2003-04-08
Mailto: FrogKiller@sohu.com
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-04-08 01:21
社区公告
暂无公告