• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Reference to Session Attribute

 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Servlet setting the following attribute:



Now in another Servlet I want to get this attribute but I can not find the correct syntax. The follow is incorrect.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you say so.
 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If you say so.


It gives me the message

Cannot convert from Object to boolean
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As getAttribute() returns an Object, you'll need to cast it to Boolean.
 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:As getAttribute() returns an Object, you'll need to cast it to Boolean.


This


Gives same type of message:

Type mismatch: cannot convert from Object to Boolean

If I do


I get
The constructor Boolean(Object) is undefined

This does not cause errors but is it the correct way



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I said cast not construct. Basic Java:


 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I said cast not construct. Basic Java:




Sorry for misunderstanding. Thanks, works great.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic