Solved

set zero to session variable

Posted on 2006-11-01
7
271 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
0
Comment
Question by:jaggernat
  • 4
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 350 total points
ID: 17851786
You need to do


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

Author Comment

by:jaggernat
ID: 17851891
so u think code is OK

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17851916
Apart from the line i changed
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:CEHJ
ID: 17851958
:-)

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

Author Comment

by:jaggernat
ID: 17851976
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 17851991
First of all, why don't you do

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

?
0
 
LVL 10

Author Comment

by:jaggernat
ID: 17852100
oh yea, thats right.

thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now