Solved

Session variable question

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
using if condition without JSTL 2 119
how to exclude a file using regex 5 123
java operators 3 129
login jsp example 24 105
Configuring Remote Assistance for use with SCCM
Check out this step-by-step guide for asking an anonymous question on Experts Exchange.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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