wood burning stoves 2.0*
The moose likes JSP and the fly likes How to retain the old values? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to retain the old values?" Watch "How to retain the old values?" New topic

How to retain the old values?

Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
I'm creating a quiz application,I'm displaying one question per page and after the user clicks next i increnent a counter which is used to iterate over the collection of Question objects,and the next Question with options is displayed...I also want a previous functionality so i have a Previous button in the JSP,when i click the previous button i decrement the counter and the Page is generated again.But i want to retain the user's options.

Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

You could save his/her options in session scope or the database and then display them again. I think it would be better if the client browser handles what question should be chosen next with the use of parameters (hidden if necessary). That way you dont have to increment or decrement counts, unless of course the collection of questions is generated randomly.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
In my online exam applications I create an object to hold each user's information - present question number, answers so far, indexes of each question in the main question script, etc. - Naturally the reference to the object is stored in the session and thats the only thing that is stored there. This approach lets the user move backwards and forwards through the test, jump to a marked question, etc.

By making the object Serializable you have the possibility of saving and resuming the test.

Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Thanks Bill and John,
I will try it out using Bill's approach and get back to you.

I agree. Here's the link: http://aspose.com/file-tools
subject: How to retain the old values?
Similar Threads
login page
Retain drop down values in JSP
Object does not support property error!
Instantiate object without scriptlet
How to do database pagination using JSTL tags