Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access session and context in simple utility class  RSS feed

 
Manoj Amrutkar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have one simple class(on server offcourse) say Chat.java, Now i want access the session and context variables through that class how can i do it?
whether it will require any extending or implementing?
You must have got tangled that when i can have a servlet why should i need a utility class. The problem is i am using DWR and using DWR i am accessing that class's methods in javascript on client side?

Hope i am clear in my wordings

Thanks in advance for your kind reply.

Manoj Amrutkar
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, i guess you can't access these objects unless you have not extended that class from GenericServlet.

The class is running under JVM which does not have to deal with any session/context objects. All these are being dealt by the CONTAINER which is running on JVM. so to access those objects your class should be in that container and the only way to make your class in that container you have to tell that it is "SERVER SPECIFIC CLASS" i.e a servlet.

there is some other way, you can pass those objects in as arguments to that class, but i am not sure will those work there properly or not.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extending the class from a servlet superclass will not work unless the class is to be used as a servlet. If it's a utility class, the only way is to pass the contexts as parameters. And since the signatures are controlled by what DWR generates, you may be stuck.

It's been a while since I've done any tinkering with DWR, you might want to poke around in its docs to see if there's a way to make its generated methods hook up to the servlet contexts.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!