my dog learned polymorphism*
The moose likes Servlets and the fly likes HttpSessionBindingListiner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSessionBindingListiner" Watch "HttpSessionBindingListiner" New topic
Author

HttpSessionBindingListiner

Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
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

Joined: Jan 10, 2002
Posts: 61654
    
  67

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
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
 
Don't get me started about those stupid light bulbs.
 
subject: HttpSessionBindingListiner