krazy Koder
krazy Koder

Reputation: 43

How to find session variable present or not

How I can find values is set to variable in session or not?

if(session.getAttribute("tot_demand"))//need to change

  //if value is already set then do this.

else

  //if not set then do this.

What do I need to write, for the above code to work?

Upvotes: 2

Views: 1475

Answers (1)

Bozho
Bozho

Reputation: 597026

Compare to null:

if (session.getAttribute("tot_demand") != null) {
   // already set
} else {
   // not yet set
}

Upvotes: 6

Related Questions