This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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?
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 ]
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
posted
0
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:
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.