Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

set zero to session variable

hi experts

this is my scenario
in my jsp i have
<c:set var="cartobject" value="${cart.lineItemsCount}" scope="session"/>    

in my java class i am trying to set cartobject to zero, but it doesnt seem to work

this is my code in java class

if ((String) session.getAttribute("cartobject") != null)
              {
                    
                   String cartobj = (String) session.getAttribute("cartobject");
                  System.out.println("Value of cartobject before making zero==="+cartobj);
                  session.setAttribute("cartobj","0");
                  System.out.println("Value of cartobject after making zero==="+cartobj);

              }


console output :

Value of cartobject before making zero===1   // this is fine .

Value of cartobject after making zero===1  // this is supposed to be zero as in above code , but it shows 1.

any ideas

thanks
J
0
jaggernat
Asked:
jaggernat
  • 4
  • 3
1 Solution
 
CEHJCommented:
You need to do


System.out.println("Value of cartobject after making zero==="+session.getAttribute("cartobj"));
0
 
jaggernatAuthor Commented:
so u think code is OK

0
 
CEHJCommented:
Apart from the line i changed
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CEHJCommented:
:-)

Try not to call getAttribute twice. Do you need to call it at all, since your objective is to set it?
0
 
jaggernatAuthor Commented:
Do you mean i should avoid this line :   String cartobj = (String) session.getAttribute("cartobject");

and directly put it like this

session.setAttribute((String) session.getAttribute("cartobject"),"0");


0
 
CEHJCommented:
First of all, why don't you do

session.setAttribute("cartobject", "0");

?
0
 
jaggernatAuthor Commented:
oh yea, thats right.

thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now