• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having problems with arrays in sessions

 
Udayaditya Barua
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have a website which is a maths tutorial. In short, there are addition,subtraction,multiply and division. One servlet generates a problem and sends it to the client.Now, when the user enters the answer another ajax request is sent to a different servlet. This servlet, maintains the score for CORRECT answers and WRONG answers in sessions. I though it wud be better to create an array for CORRECT and WRONG since, there will be too many variables each for correct/wrong addition,subtraction etc.
I have 2 arrays:
I am storing these arrays in sessions. heres the rest of the code..

Similarly for subtraction,mul,div. The problem is, the values dont get added!. I WANT them to be replaced with the new ADDED values. Like a counter.. Can anyone help me out??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use real words when posting to the forums. Abbreviations such as "wud" in place of "would" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
 
Udayaditya Barua
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No apologies are necessary. The guideline is there to help you get better and faster answers.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see code like:



but it looks like correctScoreArray is an instance variable and is thus used for all requests. It is always there and does not need to be put in the user's session.

I see local variable creation like:



but I dont understand what you are trying to do with it.

Bill
 
Udayaditya Barua
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
I see code like:



but it looks like correctScoreArray is an instance variable and is thus used for all requests. It is always there and does not need to be put in the user's session.

I see local variable creation like:


but I dont understand what you are trying to do with it.

Bill


getCorrectScoreSessVar is the variable used to collect the value of the session. I am incrementing that and storing the new value in the session. I've removed the correctScoreArray usage in the code. Just trying to implement multiple counters based on the option(if else). Can you tell me a better way to do it?
[ December 21, 2008: Message edited by: Udayaditya Barua ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I will tell you how I keep track in my own online tests.

I wrote a class which represents EVERYTHING about a single user's test taking process.

Each user gets an instance so only one reference needs to be saved and recovered from the session.

This class is Serializable so the servlet container can manage it correctly and I can save tests in progress to be resumed later.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic