Solved

Checking to see if the session is valid and not NULL

Posted on 2011-09-28
6
201 Views
Last Modified: 2012-05-12
How can I check to make sure that my session is valid and not null?
0
Comment
Question by:jkteater
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 36717968
Something like
HttpSession s = req.getSession(false);
boolean validSession = (s != null);

Open in new window

0
 

Author Comment

by:jkteater
ID: 36718318
can you print out anything related to the session?

HttpSession s = req.getSession(false);

System.out.println( s.toString());
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36718347
You cann printa arrayy of names:
String [] ss = session.getValueNames();
for(String s: ss)System.out.println(s);

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 50 total points
ID: 36718405
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
 

Author Comment

by:jkteater
ID: 36718427
Thanks to Both of you
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814180
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login form jsp example 2 48
going to wrong jsp page 2 46
restrict decimal places for double datatype 10 29
Java Inheritance super keyword use 8 30
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question