| Author |
boolean variable in session
|
Anurag Mishra
Ranch Hand
Joined: Jun 16, 2003
Posts: 121
|
|
Hi, Can anyone tell me how Can I retriev a session variable as boolean. for Example I am settin a bolean value viewPermission as... boolean viewPermission = true; session.setAttribute("VIEW",viewPermission+""); How Can i get this Value in boolean form Session in a different Page boolean getviewPermission = ???; thanks for all your help. Anurag
|
SCJP 1.2
|
 |
Anurag Mishra
Ranch Hand
Joined: Jun 16, 2003
Posts: 121
|
|
Hi All, I got the answer for this question just posting so anybody who needs can check this. Get the Value in string format to get session Variable use String viewPermision = (String)session.getAttribute("ls_viewPermission"); if(updatePermision.equals("true")) { //do What ever you want } thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56183
|
|
|
Converting a boolean to and from a string for this purpose is ridiculous. Investigate the use of the Boolean object.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Satya Komirisetti
Greenhorn
Joined: Apr 23, 2004
Posts: 11
|
|
javax.servlet.http.HttpSession ses= request.getSession(true); boolean viewPermission = true; ses.setAttribute("VIEW",viewPermission+""); /* boolean--> Sring[I]*/ String sobj=(String)ses.getAttribute("VIEW"); [I]/*obtain Session Atribute value in String Obj,then convert into Boolean Obj and extract the booelan value*/ Boolean bobj = new Boolean(false); bobj= bobj.valueOf(sobj); boolean b2 =bobj.booleanValue(); [ May 24, 2004: Message edited by: Satya Komirisetti ]
|
satya
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56183
|
|
No, no, no. Like this:
|
 |
Wendal Park
Ranch Hand
Joined: Aug 28, 2001
Posts: 39
|
|
Agree with Bear ... In addition, if you use that variable just for one page transition, you may consider using request.setAttribute("myFlag", new Boolean(true)) and (Boolean)request.getAttribute("myFlag") instead of storing it in session. The main point here is that the variable is bound to that specific request, and is not public to other pages.
|
MSc, BSc, SCJP 1.4<br /> <img src="graemlins/banghead.gif" border="0" alt="[banghead]" /> SCBCD
|
 |
Anurag Mishra
Ranch Hand
Joined: Jun 16, 2003
Posts: 121
|
|
thanks a lot for your replies guys. thanks Anurag
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
Originally posted by Bear Bibeault: No, no, no. Like this:
Better use You will avoid creating more Boolean obejcts.
|
Groovy
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12267
|
|
Even simpler - use the presence of the attribute as a flag if(viewPermission ) session.setAttribute( "VIEW","VIEW" ); else session.removeAttribute( "VIEW" ); then you can say if( session.getAttribute("VIEW") != null ){ ... Bill
|
 |
Kevin Biesbrock
Greenhorn
Joined: Nov 10, 2010
Posts: 4
|
|
I know this is ancient, but I feel it appropriate to "update" this thread a bit.
Bear Bibeault wrote:No, no, no. Like this:
This would be more efficient like so:
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56183
|
|
Vamsi Krishna Varma, Your post was moved to a new topic.
|
 |
 |
|
|
subject: boolean variable in session
|
|
|