Solved

Session variable question

Posted on 2006-11-28
3
220 Views
Last Modified: 2010-04-01

Hi all,

Im trying to amend a variable that is stored in a session. My current method is get the session variable in a string, add my new value to the string and overwrite the session variable with this new string. This is seems a overkill.
Is there a better method?

My current approach:

String var = getSessionVar();
session.removeAttribute("currentSession");
String newVar = " - "+val;
session.setAttribute("currentSession", newVar);

Thanks.
0
Comment
Question by:CtrlCtrlV
3 Comments
 
LVL 10

Accepted Solution

by:
mbvvsatish earned 125 total points
ID: 18027187
no need to remove the attribute.
session.setAttribute replaces if one already exists.

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html#setAttribute(java.lang.String,%20java.lang.Object)

0
 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 75 total points
ID: 18027742
session.setAttribute("currentSession", session.getAttribute("currentSession") + " - " + newVar);
0
 

Author Comment

by:CtrlCtrlV
ID: 18028011

thanks ;-)
0

Featured Post

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

Join & Write a Comment

Suggested Solutions

A Short Story about the Best File Recovery Software – Acronis True Image 2017
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

23 Experts available now in Live!

Get 1:1 Help Now