Session management is one of the most important aspect of web application development. I understood the importance of session management when I was working on my recent project, quiz engine.
The key points for session management are:
1) Whenever a browser is opened, only one session will be created for every tab of the browser.(I tried it for mozilla firefox).
2) Until and unless you close the browser or invalidate the session through Session's invalidate() method, the same session will be used.
3) If your application has a login page through which a user or administrator logs in then you should provide all the information in the session's attribute.
the Session object has lots of functions through which session management can be done.
Example:
String getId() : This method returns an id for the session created.
Long getLastAccessedTime() : This method tells us the time in milliseconds which have passed since 1970 (I was amazed to know this fact!!) to the last time the current session was accessed.
Long getCreationTime() : Returns the number of milliseconds passed since 1970 to the time when the session was created.
I used these methods and setAttribute() and getAttribute() methods quite often in my project and this was very helpful. Through this every user had his own session attributes having different values and the project was running very smooth. When the user ends the quiz I invalidated the session. Thus he couldnt go back from the browser's back button and change the answers once his time was over or he ended the quiz.

No comments:
Post a Comment