0

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.

Community
  • 1
  • 1
user3046703
  • 23
  • 1
  • 1
  • 8

1 Answers1

0

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.

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • 1
    thanks for your reply.I looked the site pusher.com but could not find any tutorial related wit Java servlet.Can you give another push service name that includes some examples or tutorial? – user3046703 Mar 11 '14 at 22:05