如何查找会话变量是否存在

时间:2010-08-30 11:41:46

标签: jsp servlets

如何在会话中找到值设置为变量?

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

  //if value is already set then do this.

else

  //if not set then do this.

我需要编写什么才能使上述代码生效?

1 个答案:

答案 0 :(得分:6)

null比较:

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