• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

boolean variable in session

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, no, no. Like this:

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot for your replies guys.


thanks
Anurag
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
No, no, no. Like this:



Better use


You will avoid creating more Boolean obejcts.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vamsi Krishna Varma,
Your post was moved to a new topic.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic