• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpSessionBindingListiner

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic