This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes next and prev functionality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "next and prev functionality" Watch "next and prev functionality" New topic

next and prev functionality

Anu Pasricha

Joined: Jul 08, 2002
Posts: 13
I am converting a Visual Basic project into servlets. In that i have a form with next, previous, add delete etc. How should i write the functionality for next anmd previous. How do i get to know on which record next is clicked.
I am calling the same servlet on click of buttons.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13025
Just put a hidden variable in your form so you can find out where the request is coming from. Hidden variables are very handy for this sort of problem.
peter greaves
Ranch Hand

Joined: Sep 27, 2002
Posts: 51
as bill says, you need to maintain client state across http which is a stateless protocol. the state you need is two fold:
1. what is the current record?
2. what is the direction (next or previous)?
you have a number of choices for either of these:
1. as bill says, use the hidden field in the html page - you will need a <form> for this and you might not be generating one if your data is r/only.
2. use the query string and analyse this in doGet of the servlet to determine the direction of travel and the current pos e.g.
where dir is either "next" or "prev", and rec is something that identifies the current record. something like this should work for you.
3. cookies - store the info in a cookie. a bit messy and i would avoid it.
hope this helps,

SJCP 1.2
I agree. Here's the link:
subject: next and prev functionality
It's not a secret anymore!