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.
@Bear Bibeault
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
@Nikhil Pasupukuntla
I learnt how to add a breakpoint but not how to test it. Please help.
@Stefan Evans
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?
Gaurav Wadhwani wrote: What a time waste, kept thinking there is some logical error and it was some typing mistake. Anyway finally found and learned a lesson Thank you guys
This happens many of the times..and it shooks our head..by thinking where is the mistake...