What i am trying to make is a quiz. For Fetching the records from the same location from where the user quits, I need to maintain a session. So i am using a attribute "nq" which increments each time a question is answered. However, the initial value of nq will be null so i change it to 1 to fetch the first record. And increment it then on.
I get NullPointerException. If i get it only the first time I execute its understandable because of the above reason but If I close and start again even before session expires, i get it again. Why so?
There should be no NullPointerException again as it can fetch the value of nq during the session.
Also am i doing this the right way?
Gaurav Wadhwani wrote:If i get it only the first time I execute its understandable because of the above reason
but If I close and start again even before session expires, i get it again. Why so?
What defines a session?
Most often it is stored in a session cookie which is lost when you finish the browser session.
So closing the window and starting again issues you a new session, even if the old one is still active, because it knows nothing about the old one.
Joined: Sep 21, 2010
Sorry for the very late reply everyone.
Do you really think that "nq" is a good name for anything?
Yes its a dumb name...only for testing purposes.
Instance variables in a servlet? Generally bad news!
Yes, and what i want in my application is to give one DB connection to every user but i dont know how to give a DB connection in a session. Please help
I learnt how to add a breakpoint but not how to test it. Please help.
If the session cookie is lost on closing and restarting then how is it possible that i get to continue with the same question i left at. If i close on question 4 -> close and start it again i get question 5 . So it has session and the cookie available why then a null pointer Exception?