Note: This approach is very old; Java/JSP scriptlets were deprecated a long time ago. I don't have time to update this article to the correct, modern approach, but I hope this JSP session example will point you in the right direction.
Every once in a while I'm asked something like, "How can I tell if I have a valid user session in my JSP code?"
This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.