<%@ page import="java.util.ArrayList,
java.util.Iterator,
java.util.List,
java.util.Hashtable"%>
<%
ArrayList arrayList = null;
/* Start of comments that need to removed */
Hashtable hashtable = new Hashtable(50);
for(int i=0; i<50 ; i++)
{
hashtable.put(i+"","Image Name"+i);
}
arrayList = new ArrayList(hashtable.values());
/* End of Comment code that needs to be removed */
// UNCOMMENT BELOW CODE
/*
if(null != request.getParameter("Name"))
{
//Get the Hashtable from the DB if requestParameter is null
Hashtable imagenames = image.getNames(imgName, imgId, imgacc);
//Get the values from Hashtable and store it in ArrayList
arrayList arrayList = new ArrayList(imagenames.values());
//Store the ArrayList into session Object so that you can avoid DB calls from second call to the same page
session.setAttribute("arrayList", arrayList);
}else{
// get the ArrayList from session
arrayList = (ArrayList)session.getAttribute("arrayList");
}
*/
boolean check = true;
int arrayListSize = arrayList.size();
// Number of Records that need to displayed per page
// make the increment value 5 and check it will display only 5 records per page
int increment = 2;
int fromIndex = 0;
int toIndex = increment;
String uri = request.getRequestURI();
String previous= "Previous";
String next = "Next";
List displayList = null;
if( null != request.getParameter("next"))
{
fromIndex = Integer.parseInt(request.getParameter("next"));
toIndex = increment + fromIndex;
if( toIndex+1 > arrayListSize)
{
toIndex = arrayListSize;
check = false;
}
if( fromIndex > arrayListSize)
fromIndex = 0;
}
if( null != request.getParameter("prev"))
{
toIndex = Integer.parseInt(request.getParameter("prev"));
fromIndex = toIndex - increment;
}
if(arrayListSize > 0)
{
if(increment > arrayListSize){
toIndex = arrayListSize;
displayList = arrayList.subList(fromIndex, toIndex);
toIndex = 0;
}else{
displayList = arrayList.subList(fromIndex, toIndex);
}
}
if(fromIndex != 0)
previous = "<a href="+ uri +"?prev="+ fromIndex +"> Previous </a>";
if(toIndex != 0 && check)
next = "<a href="+ uri +"?next="+ toIndex +"> Next </a>";
out.println("Total Size of ArrayList is " + arrayListSize);
out.println("<br>");
//out.println(displayList);
/* out.println("<br>");
out.println(next);
out.println("<br>");
out.println(previous); */
%>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="43%" id="AutoNumber1">
<caption><%=arrayListSize%></caption>
<tr>
<td width="53%">
<p align="center"><%=next%></td>
<td width="47%">
<p align="center"><%=previous%></td>
</tr>
<% Iterator iterator = displayList.iterator();
while(iterator.hasNext()){
String s = iterator.next().toString();
%>
<tr>
<td width="100%" colspan="2"><img src="servername:port/contextpath/servlet/getImage?imgname=<%=s%>" width="640"></td>
</tr>
<%
}%>
</table>