Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

boolean variable in session  RSS feed

 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Converting a boolean to and from a string for this purpose is ridiculous. Investigate the use of the Boolean object.
 
Satya Komirisetti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, no, no. Like this:

 
Wendal Park
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot for your replies guys.


thanks
Anurag
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
No, no, no. Like this:



Better use


You will avoid creating more Boolean obejcts.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vamsi Krishna Varma,
Your post was moved to a new topic.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!