Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes Why it can't paging?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Why it can Watch "Why it can New topic
Author

Why it can't paging?!

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi everyone:
I have a guestbook using mysql.I want to paging and each page have six record.But it remain the first page when I click the "next page"!But I have eighteen record in all.Why?My jsp code is:
////////////////////////////////////////main.jsp///////////////////////////////////////////////
........ ........... ........... ......... ........... .......... .......... ..........
<%
String sql="select * from statement where fatherid is null";
String sqlnum="select count(*) from statement";
ResultSet rs;
int numCount=0;
int pageSize=6;
int intpage=1;
String strPage="";
rs = lyo.executequery(sql);
while(rs.next()){
%>
<tr><%String sid=rs.getString("id");%>
<td><a href="/lyojsp/viewtitle.jsp?id=<%=sid%>"><%=rs.getString("title")%></a></td>
<td><%=rs.getString("content")%></td>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("time")%></td>
</tr>
<%
}
rs=lyo.executequery(sqlnum);

if(rs.next()){
numCount=rs.getInt(1);
if(intpage>numCount)
intpage=numCount;
}
int pageint=(numCount+pageSize-1)/pageSize;
if(intpage>numCount) intpage=pageint;
strPage=request.getParameter("id");
if (strPage==null){
intpage=1;}else{
intpage=Integer.parseInt(strPage);
if(intpage<1)
intpage=1;
}
%>
</table><h5>The Total is</h5><font color=red><%=numCount%></font><h5>record</h5><h4><%=pageint%></h4><h4>page</h4><p>
The<%=intpage%>page <%if(intpage<numCount){%><a href="/lyojsp/main.jsp?id=<%=intpage+1%>">next page</a><%}%>
<%if(intpage>1){%><a href="/lyojsp/main.jsp?id=<%=intpage-1%>">previous</a><%}%>
Why?Anyone want to help me?Thank you.


When I face C# and Java I choose Java.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
you must be doing something wrong with your calculations. I usually do not do this manually (paging), since there are existings tools that allow you to do it very easily...
For instance, I use the pager taglib, which pretty much does the same as you're trying to do. You can set up how many records you want in every page very easy without doing "complex" calculations...Have you tried it...? I'm sure your code will be a lot cleaner and it'll save you lots of times
hope it helps


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi Andres Gonzalez :
I use it but it is difficult to control.And it don't work property.When I click the "next page" the page dosn't change.Why?
I had give the tag the parameter And it have pageurl,pagenumber.
[ April 27, 2003: Message edited by: lyo lyo ]
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
It is not difficult to control once you've configured properly . you must be missing something
quick example:

this is just a quick and dirty example... have a look at the documentation, they explained all this step by step
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
sorry .. forgot to disable smiles...
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Thank you Andres Gonzalez !It works well!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why it can't paging?!
 
Similar Threads
Error with jsp and JavaBeans
Paging Mechanism Without Component
Why can I display one statement only?!
How to paging?NumberFormatException: For input string: "pageStr"
paging in jsp for multiple queries