jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes servletContext or application-trying to post a message so all end users of the app can see the post Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "servletContext or application-trying to post a message so all end users of the app can see the post " Watch "servletContext or application-trying to post a message so all end users of the app can see the post " New topic
Author

servletContext or application-trying to post a message so all end users of the app can see the post

Adrian Burlington
Ranch Hand

Joined: Jun 16, 2009
Posts: 75
Hi all,

So far I have been using the HttpSession to provide the end-user some information that *S/HE* was doing (Example, user clicked a cart - I can tell him/her whats in the cart).

I was wondering what mechanism should I use inorder to provide information to ALL users. Consider the following scenario: I'm the administrator (type of user) of the application and I wish to inform anyone who's right now using the application about something ( a message/post ).

I read that ServletContext (or application ?!? ) can do the job. But I'm not sure. How can a user write something that anyone who's using the system can see that (say in the header)? I'm looking for something like this:

Action:


//this of course doesn't really works. (I'm paraphrasing from httpsession -- <s:property value="%{#session.SER_IN_SESSION.loginName}"/>)


So once the action is performed - all end-userS should see the message "data comes here 1.2.3"

can anyone put more light, am I on the right track?
THANK YOU!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18902
    
    8

Seems to me there's two separate questions here:

1. How to put the data in a place where all users of the application can see it

2. How to make sure that all users of the application actually see it

The second question exists because a user of the application can't see any new information until they send a request to the server. The response sent from the application could then include this message.

So that implies two things:

1. You should store this message in the application context, which is common to all users.

2. Servlets which send responses should include this message, if it's present.

If you have further requirements, such as each user should only see the message once, then you'll need to build more logic into the part which sends the message and perhaps more logic into the part which stores the message into the application context.

Edit: I don't think you would use the context's initialization parameters for this, unless the message is a permanent one which is set up when you release the application. The context has attributes, if I recall right. I would use one of those if the message is going to be created long after the application starts up.
 
jQuery in Action, 2nd edition
 
subject: servletContext or application-trying to post a message so all end users of the app can see the post