2010-08-30 31 views
2

如何查找會話中是否設置了變量值?如何查找會話變量是否存在

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

    //if value is already set then do this. 

else 

    //if not set then do this. 

對於上面的代碼工作,我需要寫些什麼?

回答

6

比較,以null

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