|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
Java的B/s开发是通常是javaweb开发,又叫J2EE开发,J2SE是手机开发。C#的C/s和B/s开发是说.net和Asp开发。。u在这里说明一点;资深一点的Java和C#程序员都明白一点js|分页|数据我的第一个jsp分页代码
jsp文件:pagedata.jsp//显现数据
javabean:DataConn.java//毗连数据库
javabean:GetCount.java//取得数据纪录数
DataConn.java文件内容:
packagealiang_org;
importjava.sql.*;
publicclassDataConn{
publicstaticConnectiongetDataConn(){
Connectionconn=null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=your","your","your");
}
catch(Exceptionex){
ex.printStackTrace();
}
returnconn;
}
}
GetCount.java文件内容:
packagealiang_org;
importjava.sql.*;
importjava.util.*;
importjava.io.*;
publicclassGetCount{
privateConnectionconn;
publicGetCount()throwsException{
conn=DataConn.getDataConn();
}
publicintgetCounter()throwsException{
intret=0;
Statementstmt=conn.createStatement();
ResultSetrset=stmt.executeQuery("selectcount(*)fromUserInfos");
while(rset.next()){
ret=rset.getInt(1);
}
returnret;
}
}
pagedata.jsp文件内容:
<%@pagecontentType="text/html;charset=gb2312"language="java"%>
<%@pageimport="aliang_org.*"%>
<%@pageimport="java.util.*"%>
<%@pageimport="java.io.*"%>
<%@pageimport="java.sql.*"%>
<html>
<head>
<title>
jsp/JavaBean分页列出数据
</title>
</head>
<bodybgcolor="#ffffff">
<h1>jsp/JavaBean分页列出数据</h1>
<hr/>
<jsp:useBeanid="dataConnection"class="aliang_org.DataConn"scope="page"/>
<jsp:useBeanid="getcounter"class="aliang_org.GetCount"scope="page"/>
<tablewidth="100%"border="1"cellpadding="0"cellspacing="0">
<tralign="center"bgcolor="#00FFFF">
<td>ID序号</td>
<td>用户名</td>
<td>暗码</td>
<td>电子信箱</td>
<tdcolspan="2">操纵选项</td>
</tr>
<%
intnowPages;//以后页
intpages;//哀求页数
intcountPerPage=10;//每页显现条数
intpageCount;//总页数
intrecordCount=getcounter.getCounter();//recordCount为总纪录数
pageCount=(int)Math.ceil((recordCount+countPerPage-1)/countPerPage);//算出总页数
//失掉哀求页
if(request.getParameter("pages")==null){
pages=1;
}else{
pages=newInteger(request.getParameter("pages")).intValue();
}
//失掉以后实践页面
if(pages>pageCount){
nowPages=1;
}else{
nowPages=pages;
}
//猎取纪录集
Connectionconn=dataConnection.getDataConn();
ResultSetrs=conn.createStatement().executeQuery("Selecttop"+countPerPage+"*fromUserInfoswhereIDnotin(selecttop"+(nowPages-1)*countPerPage+"IDfromUserInfosorderbyiddesc)orderbyIDdesc");
while(rs.next()){
intID=rs.getInt("ID");
Stringusername=rs.getString("username");
Stringpassword=rs.getString("password");
Stringemail=rs.getString("email");
%>
<tr>
<tdalign="center"><%=ID%></td>
<td><%=username%></td>
<td><%=password%></td>
<td><%=email%></td>
<tdalign="center"><ahref="modify.jsp?ID=<%=ID%>">修正</a></td>
<tdalign="center"><ahref="delete.jspID=<%=ID%>">删除</a></td>
</tr>
<%
}
//封闭毗连
rs.close();
conn.close();
%>
<formmethod="get">
<tralign="right">
<tdcolspan="6">共有<fontcolor=red><%=recordCount%></font>笔记录以后<fontcolor=red><%=nowPages%>/<%=pageCount%></font>页
<%if(pageCount>1){%>
<%if(pages>1){%>
<ahref="">首页</a>
<%}if(pages<pageCount){%>
<ahref="?pages=<%=nowPages+1%>">下一页</a>
<%}if(pages!=1){%>
<ahref="?pages=<%=nowPages-1%>">上一页</a>
<%}%>
<ahref="?pages=<%=pageCount%>">尾页</a>
<%}%>跳转到
<selectname="pages"onChange="javascript:this.form.submit();">
<%for(inti=1;i<=pageCount;i++){%>
<optionvalue="<%=i%>"<%if(nowPages==i){%>selected<%}%>><%=i%></option>
<%}%>
</select>页</td>
</tr>
</form>
</table>
<hr/>
|
|