Solved

Session variable question

Posted on 2006-11-28
3
226 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
[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
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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