Real time notification in jsp pages with tomcat server

I am newbei in JSP subject and I am using Apache application server in Eclipse with no framework.In the project, there are more than one users.I want to enable one user to send information to another user as notification.User2 should see this notification.

draft.jsp

<div style=" float: right; margin-right:600px;margin-top:20px;">
ID:&nbsp;&nbsp;<%=Id%>

Type:
 <select name="routine">
<option value="select">select</option>
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
<option value="option4">option4</option>
</select>
Name:<input type="text" name="Name"/>
Period:<textarea rows=5 cols=10 name=period></textarea>
<button>Finish</button>
</div>

Here is the part of the jsp page.When User1 click button Finish, the information will be sent to the User2.

I searced on the internet, but cannot find any useful example or tutorial related my issue. I saw that Atmosphere, comet, Jetty and Websocket can be solution but I was not able to use these and I am not totally sure, whether they are suitable for my issue or not.Should I use the long polling or short polling?

I also saw the similar question but I couldn't understand the accepted answer.Can you please give me any idea to solve this problem?And any idea will be appreciated.Thanks in advance.

Answers


The easiest way would be to use a service like pusher.com or another push service.

When user1 submits a form on your server, the controller would call

pusher.trigger('my-channel', 'my-event', 'some-message');

User2 has a web page loaded which has the pusher JavaScript library loaded and is listening to 'my-channel':

var pusher = new Pusher('YOUR_APP_KEY');
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
  alert('An event was triggered with message: ' + data.message);
});

So basically, your server notifies pusher of the event, and pusher pushes the message to the other user.

You can use Tomcat's built-in websocket support as well, but it is more work to setup.


Need Your Help

mysql millions of rows data import from one table to another table

python mysql database

I have a table, it has two millions rows data. For each row, it has a body column, it store a JSON format data. For example:

How to Handle soft keys like search , enter etc in Appium android

android testing automation appium

I am using Appium (java) to automate my android app.I am struck in a scenario where I need to enter text and press search / enter key from Soft keyboard.I tried many solutions , but none of them wo...