File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes displaying one by one record using servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "displaying one by one record using servlets" Watch "displaying one by one record using servlets" New topic

displaying one by one record using servlets

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Iam trying to display records from a database one by one. Iam using servlets to get connection to database embedded with HTML forms to display the record . Iam able to display one record first when screen appears. If i press next button or previous button i should be able to display that record in the same textfields without changing the screen.
Actually onClick function of button iam going to javascript function.Here I donot know what code should i write to display another record. I want the code for next and previous records to be displayed.
Jason Menard

Joined: Nov 09, 2000
Posts: 6450
Since you don't want to reload the screen, you're going to have to have your form page dynamically generate some javascript for you. I don't have my javascript book with me right now so I'm going to be a little vague, but it should be enough to point you in the right direction.
For the purpose of this discussion we will assume that each row of your result set has only one piece of data, and your form similarly only has one field. Just expand on the ideas i present to accurately reflect your form and data.

  1. Your servlet will have to generate a javascript array containing all the data from your ResultSet. We'll call this array data[].
  2. You will need a global javascript variable to track your current record number, initialized to 0. We'll call this variable recordNum.
  3. You need javascript methods called next() and previous(). These methods increment or decrement recordNum. These methods then call another javascript method displayRecord().
  4. displayRecord() changes the value of the form field to data[recordNum].
  5. Your form has two buttons (next and previous) that call next() and previous().

  6. For more than one item of data you could either have an array for each data item, or even better, a multidimensional array. Hope this helps.
    [This message has been edited by Jason Menard (edited March 27, 2001).]
I agree. Here's the link:
subject: displaying one by one record using servlets
It's not a secret anymore!