Two Laptop Bag
The moose likes Servlets and the fly likes Dynamic Alert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Dynamic Alert" Watch "Dynamic Alert" New topic

Dynamic Alert

Balaji Sivaprakasam

Joined: Jan 13, 2008
Posts: 8
Hai all godd evening. i need your help. i will explain the situation first. the application what i developing has only one ADMIN but there is no restrictions in the number of clients.

the problem is if the ADMIN user presses one button then somevalues must be updated in the database[that's not the problem i can manage to do it] then it should send a alert message to all the clients who are all using the application and there page must be updated according to the changes made in the database.

how can i do that? am still in the beginner level of the J2EE. so please help me to do it.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

There is no way to push things to other clients using a web application because HTTP is a stateless protocol (meaning that users are only connected to the server long enough to draw each screen, then they disconnect).

What you can do is have each page check for a "new message" status and show the alert message if there is one. Another thing that's popular these days is the AJAX poller where each page has some Javascript that makes a call to the server every n seconds to see if there are any new messages, then shows the message.

Does this help?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
While it's possible to have a web page should periodically if there are any updates (that's what AJAX does), it's not possible to push content out to pages that have been sent already.

Would it be sufficient to display the new values (or message or whatever it is) on the next page generated for those users? Then it would suffice to set a context attribute with the message, and have each request check that and display it if necessary.

[ UD: Pretty much the same as what Ben wrote, I see. ]
[ January 21, 2008: Message edited by: Ulf Dittmer ]
I agree. Here's the link:
subject: Dynamic Alert
jQuery in Action, 3rd edition