该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
信息表#container {
width: 500px;
}
#header {
background-color: #99bbbb;
height: 60px;
width: 150px;
}
#menu {
background-color: yellow;
height: 809px;
width: 209px;
float: left;
}
#content {
background-color: #F0F8FF;
height: 809px;
width: 1000px;
float: left;
}
#footer {
background-color: #99bbbb;
height: 60px;
text-align: center;
}
.divcss5 img {
width: 300px;
height: 200px
}
.out{
}
.over{
border:solid 3px red;
font-weight:bold;
cursor:pointer;
}
.aa{
list-style-type:none;
display:none;
}
.box {
width: 300px;
height: 74px;
float: left;
}
.box ul {
list-style-type: none;
margin: 0px;
padding: 0px;
}
.box li {
border:solid 2px red;
margin: 7px;
padding: 5px;
float: left;
}
request.setCharacterEncoding("GBK");
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/Student", "root", "1234");
Statement stmt = conn.createStatement();
//每页显示记录数
int PageSize = 6; //每页显示记录数
int StartRow = 0; //开始显示记录的编号
int PageNo = 0;//需要显示的页数
int CounterStart = 0;//每页页码的初始值
int CounterEnd = 0;//显示页码的最大值
int RecordCount = 0;//总记录数;
int MaxPage = 0;//总页数
int PrevStart = 0;//前一页
int NextPage = 0;//下一页
int LastRec = 0;
int LastStartRecord = 0;//最后一页开始显示记录的编号
//获取需要显示的页数,由用户提交
if (request.getParameter("PageNo") == null) { //如果为空,则表示第1页
if (StartRow == 0) {
PageNo = StartRow + 1; //设定为1
}
} else {
PageNo = Integer.parseInt(request.getParameter("PageNo")); //获得用户提交的页数
StartRow = (PageNo - 1) * PageSize; //获得开始显示的记录编号
}
//因为显示页码的数量是动态变化的,假如总共有一百页,则不可能同时显示100个链接。而是根据当前的页数显示
//一定数量的页面链接
//设置显示页码的初始值!!
if (PageNo % PageSize == 0) {
CounterStart = PageNo - (PageSize - 1);
} else {
CounterStart = PageNo - (PageNo % PageSize) + 1;
}
CounterEnd = CounterStart + (PageSize - 1);
//获取总记录数
ResultSet rs = stmt.executeQuery("select count(product.id) from product ");
rs.next();
RecordCount = rs.getInt(1);
String q = request.getParameter("q") == null ? "" : request
.getParameter("q");
rs = stmt
.executeQuery("SELECT * FROM product INNER JOIN type on type.id=product.t_id where (product.t_id like*%"
+ q
+ "%*)or (type.name like*%"
+ q
+ "%*) order by type.name,product.t_id limit "
+ StartRow + ", " + PageSize);
//获取总页数
MaxPage = RecordCount % PageSize;
if (RecordCount % PageSize == 0) {
MaxPage = RecordCount / PageSize;
} else {
MaxPage = RecordCount / PageSize + 1;
}
%>
.getParameter("q")%>"/>
全部
飞机类
通讯类
导弹类
舰艇类
机械类
int i = 1;
while (rs.next()) {
int bil = i + (PageNo-1)*PageSize;
%>
οnmοuseοut="this.className=*out*">
src="" />
商品名:
价格:
i++;
}
%>
分页显示记录
out.print("");
//显示第一页或者前一页的链接
//如果当前页不是第1页,则显示第一页和前一页的链接
if (PageNo != 1) {
PrevStart = PageNo - 1;
out.print("首页 : ");
out.print("上一页");
}
out.print("[");
//打印需要显示的页码
for (int c = CounterStart; c <= CounterEnd; c++) {
if (c < MaxPage) {
if (c == PageNo) {
if (c % PageSize == 0) {
out.print(c);
} else {
out.print(c + " ,");
}
} else if (c % PageSize == 0) {
out.print("" + c
+ "");
} else {
out.print("" + c
+ " ,");
}
} else {
if (PageNo == MaxPage) {
out.print(c);
break;
} else {
out.print("" + c
+ "");
break;
}
}
}
out.print("]");
if (PageNo < MaxPage) { //如果当前页不是最后一页,则显示下一页链接
NextPage = PageNo + 1;
out.print("下一页");
}
//同时如果当前页不是最后一页,要显示最后一页的链接
if (PageNo < MaxPage) {
LastRec = RecordCount % PageSize;
if (LastRec == 0) {
LastStartRecord = RecordCount - PageSize;
} else {
LastStartRecord = RecordCount - LastRec;
}
out.print(":");
out.print("尾页");
}
out.print("");
%>
rs.close();
stmt.close();
conn.close();
%>
更多推荐
JAVA分页查询查到最后一页_jsp模糊查询后的数据进行分页,但点击下一页后就查询全部的了...
发布评论