aspose file tools*
The moose likes JSP and the fly likes how to display next and previous records in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

how to display next and previous records in jsp

Joseph Rudman
Greenhorn

Joined: Mar 26, 2006
Posts: 13
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

Joined: Sep 16, 2004
Posts: 3636
Welcome to JavaRanch!

Do you want to display records in a pagination view or edit view?


My blood is tested +ve for Java.
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
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 ]

java j2ee job interview questions with answers | Learn the core concepts and the key areas
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
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

Joined: Mar 26, 2006
Posts: 13
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

Joined: Jan 10, 2002
Posts: 61606
    
  67

Closing this since the OP started a new thread using a different tactic.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to display next and previous records in jsp