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.

One way to get notifications is to keep polling after certain time interval. that is pull notification. But this causes unnecessary hits to server.

How can I use push notifications from server? I am using Java Servlets and JSP with Tomcat.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Nirbhay Mishra
  • 1,629
  • 3
  • 19
  • 35
  • 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,239
  • 3
  • 28
  • 51
1

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

Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
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,200
  • 2
  • 46
  • 50