Bookmark Topic Watch Topic
  • New Topic

how to display next and previous records in jsp

 
Joseph Rudman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello,

I currently create a web application that connects to a database via a servlet, the servlets stores the database records in a vector and then forwards onto a jsp. This all works OK and I can display all database record using a bean.
But I have no idea how to make the jsp be able to show first database record to begin with and then allow user to select the next record or previous record.
Could someone show me an simple example of how to do this or give me a clue on how to do this please?

Cheers joe
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Report post to moderator
Welcome to JavaRanch!

Do you want to display records in a pagination view or edit view?
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Report post to moderator
Load the records from the database in to a java collection like a List. Say you have loaded 10 objects, which means you will have 10 objects in your list. Now you know the,

totalNumber = 10;

index of the firstRecord will be 0, and the second record will 1 and so on .. and the last record will be 9. when the user clicks a next or previous button, you should increment or decrement the index to retrieve the appropriate record from the List based on the click action. There are several other strategies based on size of your records and this is one of them.

Also, google for "JSP pagination" and you should find some sample code.
[ March 26, 2006: Message edited by: ak pillai ]
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by ak pillai:
Also, google for "JSP pagination" and you should find some sample code.


Check the FAQs sections for the same.
 
Joseph Rudman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
When servlet passes user request to jsp I see very first record.
But now I want to add a next button to jsp and I thought that if user selected this next button they would see the same jsp but the user gets a null pointer error:

<FORM method="POST" action="/ProcessClients.jsp">
<jsp:useBean id="client" scope="request" class="RemoteWorkerSimple.bean.Client" />
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
<%
int increment = 0;
ArrayList Client = (ArrayList)request.getAttribute("Clients");
client = (RemoteWorkerSimple.bean.Client)Client.get(increment);
%>

Now I want to add a button to allow user to go to next entry stored in array this should then re-call the same jsp.

But I get the following error:
java.lang.NullPointerException
at org.apache.jsp.ProcessClients$jsp._jspService ProcessClients$jsp.java:109)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)

This may be a stupid question but I have no idea why I get this error.

Cheers Joe
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing this since the OP started a new thread using a different tactic.
 
    Bookmark Topic Watch Topic
  • New Topic