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
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?
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.
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
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.