• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Accessing session object from standard class

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.

Can a standalone class access the session somehow? Basically, I want to call a utility class which isn't a servlet. I want this class to return the value of a session attribute.

The utility class is going to be called by Ajax via DWR, so I won't be able to pass in the session object as an argument. So the utility class will look something like this:



Can this be done, or are there any suggestions on an alternative? Ultimately I need my javascript to be able to access a session variable.

Many thanks.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i Think TagHandler(simple/classic tag) is better option

Hope This Helps
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is NOT a good idea to pass around references to anything which is managed by the servlet container, such as request, response, or session if you can possibly avoid it.

You need to redesign your requirements for this "utility" class - getting the value of a session attribute takes very little code in your servlet.

I can't imagine what TagHandler has to do with this.

Bill
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create a Web Context Holder class that manages thread local objects of request,response,session and a filter which sets this object in Web Context holder than your utility or what ever other classes can obtain the reference to those objects from the holder.

Look at the thread http://www.theserverside.com/patterns/thread.tss?thread_id=47208.
 
reply
    Bookmark Topic Watch Topic
  • New Topic