Solved

set zero to session variable

Posted on 2006-11-01
7
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example 11 73
Chrome and Firefox Java 5 86
Eclipse with various Java releases 7 81
batch vs regular insert in spring DAO 2 46
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

733 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