• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

boolean variable in session

 
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
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
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
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, no, no. Like this:

 
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
 
Ranch Hand
Posts: 8934
Firefox Browser Spring Java
  • 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.
 
Author and all-around good cowpoke
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
 
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
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vamsi Krishna Varma,
Your post was moved to a new topic.
 
I AM MIGHTY! Especially when I hold this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!