Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionBindingListiner

 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have read that is good coding when I create HttpSession, automaticly through HttpSessionBindingListiner to fill session.Attribute with data from Database, but for example, I put data "JSmith".. that there already here, but something is wrong here those setting attribute - Netbeans told me that he canot find variable session?



p.s. and I have that User class only with getters and setters

Please help me so I can go on.. with everything else
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, session is not declared anywhere. This is Java. Just because it's in a web app doesn't change any of the rules. Variables don't appear out of thin air.

Hint: what is available when the listener executes?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you're mistaking JSP and servlets. As Bear pointed out, there is no implicit objects for servlets. Have a look at HttpSessionBindingEvent's API, there must be something in it you're looking for.
 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have read it that sesson scope isnt thread-safe, so why wouldnt I in the bindingListener insted session.setAttribute("user",u) put request.setAttribute("user",u), beacause I need that data from the database as long as user is logged, and I dont wont that bindingListener replace data in ("user",u) with new data for new user.

When I need to use syncronized? Maybe here in BindingListiner, like:



And second, I need database connection for HttpBindingListener (and for bound and for unbound), can I do that two times (for each function)?

Kind regardes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic