Pagination problem, thank you!

Category: Web Develop
 
sosmoke
2013-08-20 05:35:26

Sponsored Links
I made a page display code, but the old mistakes, do not know why, but urgently, please help us to see right!
-------------------------------
first is a Pagebean:
package com.data;

import com.db.DBConnection;
import java.util.Vector;

public class PageBean {
public int curPage; / / the current page
public int maxPage; / / maximum page
public int maxRowCount; / / maximum number of rows
public int rowsPerPage; / / number of lines per page
public Vector data = null; / / page data to display

public PageBean ()
{

}
public PageBean (DBConnection dbc, String SQLStr) throws Exception
{
this.maxRowCount = dbc.getListDataCount (SQLStr); / / get the total number of rows
this.data = dbc.getListData ();
}
/ **
* Calculate the total number of pages
* /
public void countMaxPage ()
{
if (this.maxRowCount% this.rowsPerPage == 0)
{
this.maxPage = this.maxRowCount / this.rowsPerPage;
}
else
{
this.maxPage = this.maxRowCount / this. rowsPerPage +1;
}
}
public Vector getResult ()
{
return this.data;
}
}
--------------------------------------------
Then a database link categories, including the regular operation of the database, query, update, or something:
public class DBConnection
{
private Connection conn = null;
private ResultSet rst = null;
private Statement stmt = null;
private Vector vctr = null;

public DBConnection ()
{
try
{
Context initCtx = new InitialContext ();
Context envCtx = (Context) initCtx.lookup ("java: comp / env");
DataSource ds = (DataSource) envCtx.lookup ("jdbc / qxauc");
this.conn ; = ds.getConnection ();
this.stmt = conn.createStatement ();
}
catch (Exception e)
{
System.out.println (e.toString ());
}
}
/ / getter, setter ........................
/ / pagination code used :
public PageBean listUserInfoBean (String page)
{
try
{
String ttlCntSQLStr = "select count (*) from qx_users ";
PageBean pgbn = new PageBean (this, ttlCntSQLStr);
int pageno = Integer.parseInt (page);
String SQLString =" select top ; "+ pageno * pgbn.rowsPerPage +
" * from qx_users order by userId ";
executeQuery (SQLString);
this.vctr = new Vector ();
int i = 0;
while (rstNext ())
{
if (i> ((pageno-1 ) * pgbn.rowsPerPage-1))
{
Object [] obj = new Object [16];
obj [0] = new Integer (rstGetInt ("userId" ;));
obj [1] = rstGetString ("userName");
obj [2] = rstGetString ("password");
obj [3] = new ; Integer (rstGetInt ("userRole"));
obj [4] = rstGetString ("trueName");
obj [5] = rstGetString ("idNum");
obj [6] = rstGetString ("telephone");

obj [7] = rstGetString ("gender");
obj [8] = rstGetString ("email");
obj [9] = rstGetString ("cliUnit");
obj [10] = rstGetString ("post");
obj [11] = rstGetString ("postcode");
obj [ 12] = rstGetString ("address");
obj [13] = rstGetString ("pwdQues");
obj [14] = rstGetString (" ; pwdAnsw ");

obj [15] = new Integer (rstGetInt (" activeFlg "));
this.vctr.add (obj);
}
i + +;
}
pgbn.curPage = pageno;
pgbn.data = this.vctr;
return pgbn;
}
catch (Exception e)
{
System.out.println (e.toString ());
return null;
}

}
public int getListDataCount (String SQLStr)
{
int ldc = 0;
DBConnection dbc = new DBConnection ();
dbc.executeQuery (SQLStr);
if (dbc.rstNext ())
{
ldc = dbc.rstGetInt (1);
}
dbc. ConnClose ();
return ldc;
}
public Vector getListData ()
{
return this.vctr;
}
}
---------------------------------
Here is the Servlet handling Code:
String userId = request.getParameter ("userId");
response.setContentType ("text / html; chaeset = gb2312");
response.setCharacterEncoding (" gb2312 ");
if (userId! = null)
{
if (userId.equalsIgnoreCase (" -1 ")) / / Read all user information
{
try
{
String jmpage = request.getParameter ("page");
if (jmpage == null)
{
jmpage = "1";
}
DBConnection dbc = new DBConnection ();
PageBean pb = dbc.listUserInfoBean (jmpage);
request.setAttribute (" ; pagedata ", pb); / / will pagebean write session
dbc.ConnClose ();
RequestDispatcher dis = request.getRequestDispatcher (" / admin / viewuser.jsp ? userId = -1 & page = 1 ");
dis.forward (request, response);

}
catch (Exception e)
{
System.out.println (e.toString ());
PrintWriter pw = response.getWriter ();
pw.println ("<h1> an exception! < ;/ h1> "+"
");
pw.println (" <h4> e.toString (): </ h4> "+ e. toString () + "
");
pw.println ("<h4> e.getMessage (): </ h4>" + e.getMessage () + "
");
pw.println ("<hr/>");
e.printStackTrace (pw);
}
}
else / / View profile
{
PrintWriter pw = response.getWriter ();
pw.println ("<h1> Your personal information is to view it! </ h1> ");
}
}
else
{
PrintWriter pw = response.getWriter () ;
pw.println ("<h1> request parameter error! </ h1>");
}
------------ -------------------
control display jsp code:
<div id="innerPage">
< ; a href = "<c:url value="admin/main.jsp" />" target = "mainFrame"> <- Back to Home </a> ;
<h1> your query data: </ h1>
<table>
<tbody>
<%
Vector v = pagedata.getResult ();
if (v! = null)
{
Enumeration e = v.elements ( );

while (e.hasMoreElements ())
{
Object [] obj = (Object []) e.nextElement ();%>
<tr>
<td> <% = obj [0] %> </td>
<td> <% = obj [1]%> </td>
<td> <% = obj [2]%> </td>
<td> <% = obj [3]%> </td>
<td> <% = obj [4]%> </td>
<td> <% = obj [5] %> </td>
<td> <% = obj [6]%> </td>
<td> <% = obj [7]%> </td>
<td> <% = obj [8]%> </td>
<td> <% = obj [9]%> </td>
<td> <% = obj [10] %> </td>
<td> <% = obj [11]%> </td>
<td> <% = obj [12]%> </td>
<td> <% = obj [13]%> </td>
<td> <% = obj [14]%> </td>
<td> <% = obj [15] %> </td>
</tr>
<%}
}
else
{%>
query process errors!

& nbsp & nbsp & nbsp & nbsp & nbsp & nbsp & nbsp & nbsp - from viewuser.jsp
<%
}% >
</tbody>
</table>
<% / / page navigation%>
<% if (pagedata.maxPage ! = 1) {%>
<div id="pageBar">
<form name = "PageForm" action = "/ servlet / yourpackage . yourservlet "method =" post ">
<% @ include file =" pageBar.inc "%>
</form>
</div>
<%}%>
</div>
-------------------- ----------------
flip control code:
<script language="JavaScript">
<! -
function jumping ()
{
document.PageForm.submit ();
return;
}
function gotoPage (pageno)
{
document.PageForm.jumpPage.value = pageno;
document.pageForm.submit ();
return;
}
</script>
s <% = pagedata.curPage%> / <% = pagedata.maxPage%> page
<% if (pagedata.curPage == 1) {out.print ( "Previous");} else {%>
<A HREF = "javascript: gotoPage (1) "> Home </A>
<A HREF =" javascript: gotoPage (<% = pagedata.curPage-1%>) "> Previous </A>
<%}%>
<% if (pagedata.curPage == pagedata.maxPage) {out.print ("Next End ");} else {%>
<A HREF =" javascript: gotoPage (<% = pagedata.curPage + 1%>) "> Next </A>
<A HREF =" javascript: gotoPage (<% = pagedata.maxPage%>) "> Last Page </A>
<%}%>
Go <SELECT name="jumpPage" onchange="Jumping()">
<% for (int i = 1; i <= pagedata.maxPage; i + +) {
; if (i == pagedata.curPage) {
%>
<OPTION selected ; value = <% = i% >> <% = i%> </OPTION>
<%} else {%>
<OPTION value = <% = i% >> <% = i%> </OPTION>
<%}}%>
</SELECT> page


Sponsored Links

focuseric
2013-08-20 05:48:12
Halo, failed to provide data will not break out the sql execute it and see what ah
wdwdwdwdwd001
2013-08-20 05:58:27
at least he should stick out the wrong way, oh you who dare to answer
a1275111018
2013-08-20 06:08:58
String SQLString = "select top" + pageno * pgbn.rowsPerPage +
"* from qx_users order by userId";
is an access to your right, the above statement can take the first few pages of the required data?
I think it is impossible, access is not engaged, but certainly above is wrong. .
jiayuyao1
2013-08-20 06:20:10
.........
head look big
first posted error
wwwwwwPP
2013-08-20 06:33:40
back tcmis (Do not you forget it? ):
control code can take the following specific data page.
leichangyong
2013-08-20 06:49:54
I also want to paste the error ah, but just failed to provide data only ah!
in the display, I also used the Vector v = pagedata.getResult (); if (v! = null) {} judgment, the result is not null v ah. Please master guiding!
ysl19730701
2013-08-20 07:00:41
Which can look tired on the program's logic there is no problem ah?
dlees
2013-08-20 07:17:58
this tab really ugly (code)
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.