Tar*_*pta 19 java jsp spring-mvc push-notification
目前我正在开发一个使用Spring 3.1和Hibernate 4的Web应用程序.
根据要求,我想在JSP页面上实现像Facebook这样的推送通知.如果您有任何建议,请同时列出兼容的浏览器及其版本.
小智 23
如果您可以升级到或正在使用JDK 7我建议使用Vert.x Vertx.io,请在客户端使用Sockjs.Vert.x有一个完整的sockjs服务器实现,我将尝试建议一种实现这个的方法,其余请看文档
服务器实现可能是这样的
Vertx vertx = Vertx.newVertx();
EventBus eventBus = vertx.eventBus()
HttpServer server = vertx.createHttpServer();
JsonArray permitted = new JsonArray();
permitted.add(new JsonObject());
SockJSServer sockJSServer = new DefaultSockJSServer(vertx, server);
sockJSServer.bridge(new JsonObject().putString("prefix", "/pusher"), permitted, permitted);
server.listen(<some port>);
Run Code Online (Sandbox Code Playgroud)
在客户端,在文档加载时注册一个像这样的处理程序
function () {
if (!eb) {
eb = new vertx.EventBus("http://<your_host>:<your_port>/pusher");
eb.onopen = function() {
console.log("connected")
};
eb.onclose = function() {
console.log("Not connected");
eb = null;
};
}
Run Code Online (Sandbox Code Playgroud)
}
然后你可以在任何地址注册一个处理程序 - 这里的地址可以是任何东西,假设它是"AwesomeNotifications"
function subscribe(address) {
if (eb) {
eb.registerHandler(address, function(msg, replyTo) {
console.log("Reply recieved")
});
}
}
Run Code Online (Sandbox Code Playgroud)
完成所有设置后,您现在可以使用我们之前创建的事件总线将任何数据从服务器推送到此地址
eventBus.publish("AwesomeNotifications", new JsonObject(<some hashmap to serialize>))
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
SAN*_*NN3 13
您可以使用HTMl5服务器发送选项.在这里您可以获得更多细节
服务器发送选项:
http://www.w3schools.com/html/html5_serversentevents.asp
服务器发送的Java服务:
教程:
http://peaktechie.blogspot.in/2012/04/small-tutorial-on-html5-server-sent.html
HTML5支持的浏览器:
我最近一直在研究这个问题.基于事件的方法是构建单页Web应用程序的一个很好的方法,但也可用于多页面Web应用程序.
有很多方法可以做到这一点:
毫无疑问,我认为对于作者而言,整合到一个spring-mvc项目中,Atmosphere显然是最合适的.
编辑:错别字
| 归档时间: |
|
| 查看次数: |
31381 次 |
| 最近记录: |