mysql模糊查询后分页_jsp模糊查询后的数据进行分页,但点击下一页后就查询全部的了...
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
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();
%>
總結
以上是生活随笔為你收集整理的mysql模糊查询后分页_jsp模糊查询后的数据进行分页,但点击下一页后就查询全部的了...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql timestamp 用法_M
- 下一篇: vue 父刷新子_父组件中vuex方法更