mysql模糊查询后分页_jsp模糊查询后的数据进行分页,但点击下一页后就查询全部的了...
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
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();
//每頁(yè)顯示記錄數(shù)
int PageSize = 6; //每頁(yè)顯示記錄數(shù)
int StartRow = 0; //開始顯示記錄的編號(hào)
int PageNo = 0;//需要顯示的頁(yè)數(shù)
int CounterStart = 0;//每頁(yè)頁(yè)碼的初始值
int CounterEnd = 0;//顯示頁(yè)碼的最大值
int RecordCount = 0;//總記錄數(shù);
int MaxPage = 0;//總頁(yè)數(shù)
int PrevStart = 0;//前一頁(yè)
int NextPage = 0;//下一頁(yè)
int LastRec = 0;
int LastStartRecord = 0;//最后一頁(yè)開始顯示記錄的編號(hào)
//獲取需要顯示的頁(yè)數(shù),由用戶提交
if (request.getParameter("PageNo") == null) { //如果為空,則表示第1頁(yè)
if (StartRow == 0) {
PageNo = StartRow + 1; //設(shè)定為1
}
} else {
PageNo = Integer.parseInt(request.getParameter("PageNo")); //獲得用戶提交的頁(yè)數(shù)
StartRow = (PageNo - 1) * PageSize; //獲得開始顯示的記錄編號(hào)
}
//因?yàn)轱@示頁(yè)碼的數(shù)量是動(dòng)態(tài)變化的,假如總共有一百頁(yè),則不可能同時(shí)顯示100個(gè)鏈接。而是根據(jù)當(dāng)前的頁(yè)數(shù)顯示
//一定數(shù)量的頁(yè)面鏈接
//設(shè)置顯示頁(yè)碼的初始值!!
if (PageNo % PageSize == 0) {
CounterStart = PageNo - (PageSize - 1);
} else {
CounterStart = PageNo - (PageNo % PageSize) + 1;
}
CounterEnd = CounterStart + (PageSize - 1);
//獲取總記錄數(shù)
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);
//獲取總頁(yè)數(shù)
MaxPage = RecordCount % PageSize;
if (RecordCount % PageSize == 0) {
MaxPage = RecordCount / PageSize;
} else {
MaxPage = RecordCount / PageSize + 1;
}
%>
.getParameter("q")%>"/>
全部
飛機(jī)類
通訊類
導(dǎo)彈類
艦艇類
機(jī)械類
int i = 1;
while (rs.next()) {
int bil = i + (PageNo-1)*PageSize;
%>
οnmοuseοut="this.className=*out*">
src="" />
商品名:
價(jià)格:
i++;
}
%>
分頁(yè)顯示記錄
out.print("");
//顯示第一頁(yè)或者前一頁(yè)的鏈接
//如果當(dāng)前頁(yè)不是第1頁(yè),則顯示第一頁(yè)和前一頁(yè)的鏈接
if (PageNo != 1) {
PrevStart = PageNo - 1;
out.print("首頁(yè) : ");
out.print("上一頁(yè)");
}
out.print("[");
//打印需要顯示的頁(yè)碼
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) { //如果當(dāng)前頁(yè)不是最后一頁(yè),則顯示下一頁(yè)鏈接
NextPage = PageNo + 1;
out.print("下一頁(yè)");
}
//同時(shí)如果當(dāng)前頁(yè)不是最后一頁(yè),要顯示最后一頁(yè)的鏈接
if (PageNo < MaxPage) {
LastRec = RecordCount % PageSize;
if (LastRec == 0) {
LastStartRecord = RecordCount - PageSize;
} else {
LastStartRecord = RecordCount - LastRec;
}
out.print(":");
out.print("尾頁(yè)");
}
out.print("");
%>
rs.close();
stmt.close();
conn.close();
%>
總結(jié)
以上是生活随笔為你收集整理的mysql模糊查询后分页_jsp模糊查询后的数据进行分页,但点击下一页后就查询全部的了...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql timestamp 用法_M
- 下一篇: linux cmake编译源码,linu