• Post Reply Bookmark Topic Watch Topic
  • New Topic

global object available to all servlets/jsp  RSS feed

 
g forte
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am creating a chat application. I use a jsp that connects to a servlets via Ajax. One servlet receives the message that the user typed and processes it(passes to XMPP server among other things) and also Writes to an xml file specific to each pair of users. Another servlet checks and returns the chat message to the user. I also have a Servlet that checks for all users presence. So I have a servlet that Sets chat and one that Gets chat and one that Gets Presence basically. Now I need to set a global type object(I was thinking a List,Array or perhaps a StringBuffer or ??) that will store a.... (lets call it a notification). So when the SetChat servlet is called I can update this global object....and then when the GetPresence servlet is called, I can read this global object for each users name and if it exists, read the xml file with the recently added chat. I need to do this in lieu of iterating through the directory that holds all xml files and determine if the file has changed and if so read it(too much overhead).
I tried this:
I set create a StringBuffer when SetChat servlet is called and append. Each time this SetChat servlet is called I append with new string. This works fine but is only available to SetChat servlet. I tried the RequestDispatcher but I could not get it to work. Returns null...plus I think this is the wrong thing to use.
Any ideas as to what I can use here?
TIA!
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put it in application scope using ServletContext.

getServletConfig().getServletContext().setAttribute("key", valueObj);

Well if you just want to get it in the jsp where request is forwarded, then there is no need to put in application scope rather you can put it in request scope.

Naseem
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!