13

In my application I have to show a notification on a particular action taken place ?

I have to show logged in user a notification then. .

1-One way to get notification is to keep polling after certain time interval . that is pull notification.

but this causes unnecessary hits to server.

how Can I use push notification from server upon action. .? (I am using java(servlet/jsp) with tomcat)

Nirbhay Mishra
  • 1,559
  • 3
  • 18
  • 33
  • 2
    Take a look at WebSockets: http://stackoverflow.com/questions/2190500/websockets-served-by-a-servlet-container –  Apr 15 '13 at 08:27
  • You can take a look at HTML5 SSE (http://www.w3schools.com/html/html5_serversentevents.asp ) Not sure if this will solve your problem. It's basically polling, but you don't need to do it. The browser does it. – varun1505 Apr 15 '13 at 08:28

4 Answers4

8

Nowadays a promising way of client-server communication is to use Websockets.

See What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet to see some other ways together with the Websockets and for an advantages of Websockets with an introduction see An Introduction To WebSockets

Community
  • 1
  • 1
suat
  • 4,123
  • 2
  • 27
  • 48
1

You can use WebSockets for this purpose. There are multiple implementations available like jwebsocket.

Bhushan Bhangale
  • 10,651
  • 5
  • 40
  • 70
1

Take a look at the Comet model and Servlet 3.0 specification.

user2256686
  • 245
  • 1
  • 7
0

You can try Servlet3.0 Async functionality.

Here is an Chat example which does push : Servlet 3.0 Async Example

Community
  • 1
  • 1
Ramesh PVK
  • 15,050
  • 2
  • 44
  • 49