Reverse Ajax + JSP-Servlet

假装没事ソ 提交于 2020-01-10 20:11:44

问题


We are trying to create a reverse ajax in our project.

I've checked on the net and didn't find something concrete. I was unable to run any of the tutorials provided successfully.

My object is: to provide on-screen alerts (like a pop-up) when ever there is an even pushed from the server (it could be high cpu usage/ram, anything).


回答1:


The HTTP protocol (fortunately, after all) doesn't support PUSH, so it stops there.

Best what you can do is to let the client fire ajax poll requests at timed intervals I can recommend jQuery.ajax() in combination with setInterval() for this.

Alternatively (and with a bit more effort) you could make use of Comet technique (which simulates the fictive HTTP PUSH less or more). Check the appserver specific documentation/wiki using this keyword for details. Here's a Tomcat targeted example: http://wiki.apache.org/tomcat/WhatIsComet

Edit: as requested, here's a Tomcat+Comet tutorial to get started: http://www.ibm.com/developerworks/web/library/wa-cometjava/#N100CC Hope this helps.




回答2:


Here is a valuable resource



来源:https://stackoverflow.com/questions/1770785/reverse-ajax-jsp-servlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!