Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Next & Previous buttons behaviour in my jsp page

 
Mamatha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'am displaying chunk(10 records) in a page from the database.Using the Next and Previous buttons on my page , I can retrieve 10 records at a time.The problem is explained below.
* Retrieve first 10 records(1-10)
* using the Next button get next set(10-20)
* Now using browser's back button goto previous page(page with the records 1-10)
* Now use Next button.Now the expected result is to get 10-20 records page, but i'am getting 20-30 records page.
*Also the Previous button behaves in the similar manner.How should I solve this problem.
Thanks
Mamatha

------------------
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that, the Servlet cannot detect user pressing the browser's back button. When the back button is pressed, the browser just displays the old page that is in the cache and no servlet communication takes place.
You can solve this problem by maintaining some kind of record number in the request which tells you upto what record is displayed. With each request ( next/prev ) you will add or subtract 10 from the record number and store it as an attribute on the request. This way you will not lose track of what you are displaying and what you should display when the request comes in.
Just a suggestion, there might be a better way to do this
Ajith
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your name "Mamatha" does not comply with the JavaRanch naming policy. Please choose one that meets the requirements.
Ajith
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic