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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
All Courses

From novice to tech pro — start learning today.