Solved

Session variable question

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Direct mail marketing is the act of mailing materials straight to prospective customers. This wide form of marketing is one of the oldest methods of communicating with a geographic based demographic. So is it useful in 2017 and beyond?
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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