Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Session variable question

Posted on 2006-11-28
3
Medium Priority
?
229 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 500 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 300 total points
ID: 18027742
session.setAttribute("currentSession", session.getAttribute("currentSession") + " - " + newVar);
0
 

Author Comment

by:CtrlCtrlV
ID: 18028011

thanks ;-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ready to kick start your career in 2018? Add app developer skills to your resume. January’s Course of the Month features Android App Development training with hands-on learning.  Read on to learn why these skills are important.
This blog will spread awareness about Dropbox. We have given the statements based upon our experience. Along with this, there is a section of some new plans that should be added in Dropbox this year. This will make the storage service enhanced from …
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

564 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