how to done Next and Previous operations using(struts or jsp and servlets).
I have some problem with Next and Previous Operations in my application. I solve that problem by my own. But I need some more information to solve that problem.
In order to solve this problem, 1st i moved all the Dara Base records into one collection.And I set that collection Object in Session scope in Servlet file.And i dispatch the request to one jsp(Show.jsp) . The code of that is given bellow.
<%@page language="java"%>
<%@page import="java.util.*"%>
<%@page import="home.servlet.beans.*"%>
<%!
public static int no=0;
%>
<html>
<body>
<%
String s=request.getParameter("nam");
if(s==null)
s="some";
ArrayList a=(ArrayList)session.getAttribute("tv");
if(!s.equals("pre"))
{
int i=no;
%>
<table border=1>
<tr>
<th>DEPTNO</th>
<th>DNAME</th>
<th>LOC</th>
</tr>
<%
if((no+1)<a.size())
{
for(i=no;i<(no+2);i++)
{
SelectBean sb=(SelectBean)a.get(i);
%>
<tr>
<td><%=sb.getDeptno()%></td>
<td><%=sb.getDname()%></td>
<td><%=sb.getLoc()%></td>
</tr>
<%
}
no=no+2;
}
else
{
if(i<a.size())
{
for(i=no;i<a.size();i++)
{
SelectBean sb=(SelectBean)a.get(i);
%>
<tr>
<td><%=sb.getDeptno()%></td>
<td><%=sb.getDname()%></td>
<td><%=sb.getLoc()%></td>
</tr>
<%
}
}
else
{
out.println("<tr><td colspan='3'>There is no records to display</td></tr>");
}
}
}
else
{
%>
<table border=1>
<tr>
<th>DEPTNO</th>
<th>DNAME</th>
<th>LOC</th>
</tr>
<%
if(no==a.size())
no=no-1;
int i=no;
for(i=no;i>(no-2);i--)
{
if(i==-1)
{
break;
}
SelectBean sb=(SelectBean)a.get(i);
%>
<tr>
<td><%=sb.getDeptno()%></td>
<td><%=sb.getDname()%></td>
<td><%=sb.getLoc()%></td>
</tr>
<%
}
no=no-2;
if(no<0)
no=0;
}
%>
</table>
<a href="Show.jsp">next</a>
<a href="Show.jsp?nam=pre">previous</a>
</body>
</html>
If u have any other idea please reply to me. Please copy the above code andwork with your application.

