In my web application i neet to check session already exist or not.
i want to check this in my servlet and in jsp also.
is there any way to check this.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can test it with
HttpServletRequest#getSession(boolean create)withcreate=false. It will return null if not created yet.If you actually want to create the session anyway if it doesn’t exist, then just grab it and test the freshness using
HttpSession#isNew():That was how you would do it in a Servlet. In a JSP you can only test the freshness with help of JSTL and EL. You can grab the session by
PageContext#getSession()and then just callisNew()on it.or