I have this session attribute containing an Object.
I also have a session time out set to 30 minutes.
In the servlet code I wrote the code below.
I also forward this object into a JSP page and use it for another purpose. So if I refresh the page when the session is timeout, it will gives me an error too =(
The problem is, when the session is timeout and when I requested the servlet, it gives me an error stating that the object is null or empty.
Does any one knows how to mitigate this problem?
I heard that I must use a listener or a filter. But could anyone here please enlighten me how to solve this problem please.
I really appreciate your help. =)
Thank you Pros!
The full code:
I have been think for a moment and what I understood is like this
Do all professional Servlet Programmers still do this process? Or do they use another efficient and best practice way to avoid session null error?
Once again thanks for the insight
Let's say that when a user logs in we place the user's info in the session as a scoped variable:
Later, when we want to check if the user is still valid or has timed out, we'd fetch the scoped variable, but test it for null:
I got this kind of error when I call the servlet again
So it is best practice or better to check the session attribute nullity rather than checking the session object nullity.
so if the session attribute is destroyed/expired/timeout, I must create a new session attribute filled with an object and a value such as a boolean which tells the visitor is not a member. Then in a JSP page it will use that boolean information to hide the special feature and display the login/signup button.
hehehehehe sorry I made too much statement instead of an question.
The question: Is my statement correct?