Checking to see if the session is valid and not NULL

How can I check to make sure that my session is valid and not null?
jkteaterAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
Something like
HttpSession s = req.getSession(false);
boolean validSession = (s != null);

Open in new window

0
 
jkteaterAuthor Commented:
can you print out anything related to the session?

HttpSession s = req.getSession(false);

System.out.println( s.toString());
0
 
for_yanCommented:
You cann printa arrayy of names:
String [] ss = session.getValueNames();
for(String s: ss)System.out.println(s);

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
for_yanConnect With a Mentor Commented:
You may try tp print s.toString() but chances are you'll get some cryptic like Session@...(some numbers or something).
 And if you print list of stored filed names - that would be meaningful:

HttpSession session = req.getSession(false);
if(session != null){
String [] ss = session.getValueNames();
for(String s: ss)System.out.println(s);
}

Open in new window

0
 
jkteaterAuthor Commented:
Thanks to Both of you
0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.