We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

set zero to session variable

jaggernat
jaggernat asked
on
Medium Priority
342 Views
Last Modified: 2010-03-31
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
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
You need to do


System.out.println("Value of cartobject after making zero==="+session.getAttribute("cartobj"));

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
so u think code is OK

CERTIFIED EXPERT
Top Expert 2016

Commented:
Apart from the line i changed
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)

Try not to call getAttribute twice. Do you need to call it at all, since your objective is to set it?

Author

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");


CERTIFIED EXPERT
Top Expert 2016

Commented:
First of all, why don't you do

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

?

Author

Commented:
oh yea, thats right.

thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.