Solved

Checking to see if the session is valid and not NULL

Posted on 2011-09-28
6
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

734 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