jQuery in Action, 2nd edition*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "next and prev functionality" Watch "next and prev functionality" New topic
Author

next and prev functionality

Anu Pasricha
Greenhorn

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.
Bye
Regards
Anu
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
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.
Bill
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.
http://foo/.com/servlet/MyServlet?dir=next&rec=092302
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,
peter


SJCP 1.2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: next and prev functionality