wood burning stoves 2.0*
The moose likes Servlets and the fly likes Having problems with arrays in sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Having problems with arrays in sessions" Watch "Having problems with arrays in sessions" New topic
Author

Having problems with arrays in sessions

Udayaditya Barua
Greenhorn

Joined: Dec 05, 2008
Posts: 8
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

Joined: Jan 10, 2002
Posts: 61310
    
  66

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Udayaditya Barua
Greenhorn

Joined: Dec 05, 2008
Posts: 8
My apologies.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

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

Joined: Mar 22, 2000
Posts: 12791
    
    5
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

Joined: Dec 05, 2008
Posts: 8
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

Joined: Mar 22, 2000
Posts: 12791
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having problems with arrays in sessions