日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dwr消息推送和tomcat集群

發布時間:2025/7/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dwr消息推送和tomcat集群 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網友的提問:

項目中用到了dwr消息推送。而服務端是通過一個http請求后 觸發dwr中的推送方法。而單個tomcat中。服務器發送的http請求和用戶都在一個tomcat服務器中。這樣就能精準推送到每個客戶端用戶 中?,F在配置了apache集群后,通過負載均衡,apache把服務器的這個http請求也給分配給一個tomcat容器中。這樣的話,在別的tomcat容器中的用戶就接受不要消息了。有什么好的辦法讓這個請求分配給每個tomcat容器。


提取到的知識點是

dwr消息推送、apache集群、負載均衡

http://tonl.iteye.com/blog/1399027

?

使用DWR反轉實現信息推送(一)

?

除了利用Pushlet實現信息推送外,DWR反轉同樣可以實現推送。

DWR的簡單配置方法已經在以前的博客中寫過。所以這里直接貼代碼:

新建web工程,這里命名為DwrEg,包結構如下:

web.xml代碼如下:

Xml代碼??
  • <?xml?version="1.0"?encoding="UTF-8"?>??
  • <web-app?version="2.5"???
  • ????xmlns="http://java.sun.com/xml/ns/javaee"???
  • ????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"???
  • ????xsi:schemaLocation="http://java.sun.com/xml/ns/javaee???
  • ????http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">??
  • ??<servlet>??
  • ??????<servlet-name>dwr-invoke</servlet-name>??
  • ??????<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>??
  • ?????<init-param>??
  • ?????????<param-name>debug</param-name>??
  • ?????????<param-value>true</param-value>???
  • ?????</init-param>??
  • ?????<init-param>??
  • ?????????<param-name>activeReverseAjaxEnabled</param-name>??
  • ?????????<param-value>true</param-value>??
  • ?????</init-param>????
  • ?????<!--???
  • ?????<init-param>??
  • ?????????<param-name>classes</param-name>??
  • ?????????<param-value>java.lang.Object</param-value>??
  • ????????</init-param>?-->??
  • ??</servlet>??
  • ??
  • ??<servlet-mapping>??
  • ?????<servlet-name>dwr-invoke</servlet-name>??
  • ?????<url-pattern>/dwr/*</url-pattern>??
  • ??</servlet-mapping>??
  • ??<welcome-file-list>??
  • ????<welcome-file>client.html</welcome-file>??
  • ??</welcome-file-list>??
  • </web-app>??
  • ?

    dwr.xml代碼如下:

    Xml代碼??
  • <?xml?version="1.0"?encoding="UTF-8"?>??
  • <!DOCTYPE?dwr?PUBLIC?"-//GetAhead?Limited//DTD?Direct?Web?Remoting?2.0//EN"?"http://getahead.org/dwr//dwr20.dtd">??
  • <dwr>??
  • ????<allow>???
  • ????????<create?javascript="myrevsrse"?creator="new">??
  • ????????????<param?name="class"?value="com.src.MyReverse"/>??
  • ????????</create>??
  • ???</allow>??
  • </dwr>??
  • ?MyReverse.java代碼如下:

    Java代碼??
  • package?com.src;??
  • ??
  • import?java.util.Collection;??
  • ??
  • import?org.directwebremoting.ScriptBuffer;??
  • import?org.directwebremoting.ScriptSession;??
  • import?org.directwebremoting.ServerContext;??
  • import?org.directwebremoting.ServerContextFactory;??
  • import?org.directwebremoting.WebContext;??
  • import?org.directwebremoting.WebContextFactory;??
  • import?org.directwebremoting.proxy.dwr.Util;??
  • ??
  • public?class?MyReverse?{??
  • ????public?void?sendMes(String?mes){??
  • ????????System.out.println("kao?shi?si?bestllll...");??
  • ????????send("系統消息:"+mes);??
  • ????}??
  • ????public?void?send(final?String?output)?{??
  • ????????org.directwebremoting.WebContext?web?=?WebContextFactory.get();????
  • ????????String?page?=?web.getServletContext().getContextPath()+"/client.html";???
  • ??????????
  • ????????Collection?sessions?=?web.getScriptSessionsByPage(page);?????
  • ????????System.out.println("size=="+sessions.size());??
  • ???????????
  • ????????Util?utilAll?=?new?Util(sessions);????
  • ????????
  • ????????utilAll.addFunctionCall("callBack",?output);?//callBack是client.jsp里面的javascript函數,output是傳遞過去的參數??
  • ????????//utilAll.setValue("news_id",?output,?false);?????
  • ????????//這種方法也可以,直接將client.html里id為news_id的textarea的值設置為output的值???????
  • ????}??
  • ??
  • ????public?void?noticeNewOrder(int?id)?{??
  • ????????WebContext?wctx?=?WebContextFactory.get();??
  • ????????ScriptBuffer?script?=?new?ScriptBuffer();??
  • ????????script.appendScript("receiveMessages(")??
  • ????????????????.appendData(id)??
  • ????????????????.appendScript(");");??
  • ??
  • ????????ServerContext?sctx?=?ServerContextFactory.get(wctx.getServletContext());??
  • ????????Collection<ScriptSession>?pages?=?sctx.getScriptSessionsByPage("/DwrEg/client.html");??
  • ??????????
  • ????????for?(ScriptSession?session?:?pages)?{??
  • ????????????session.addScript(script);??
  • ????????}??
  • ????}??
  • }??
  • ?client.html代碼如下:

    Html代碼??
  • <html>??
  • <script?type="text/javascript"?src="dwr/engine.js"></script>??
  • <script?type="text/javascript"?src="dwr/util.js"></script>??
  • <head>??
  • <script?type="text/javascript">??
  • ??
  • ????function?callBack(data){??????
  • ???????????alert(data);?????
  • ????????}????
  • ????function?receiveMessages(id)?{??
  • ????????????$('orderNotice').innerHTML?=?"收到id為"?+?id?+?"的新訂單!";??
  • ????????????$('orderNotice').show();??
  • ????????}??
  • ?????
  • </script>??
  • </head>??
  • <body?onload="dwr.engine.setActiveReverseAjax(true);">??
  • <textarea?rows="20"?cols="20"?id="news_id"></textarea>??
  • <br?/>???
  • <div?id="orderNotice"></div>???
  • </body>??
  • </html>??
  • ?推送界面dopush.html的代碼如下:

    Html代碼??
  • <html>??
  • <script?type="text/javascript"?src="dwr/engine.js"></script>??
  • <script?type="text/javascript"?src="dwr/util.js"></script>??
  • <script?type="text/javascript"?src="dwr/interface/myrevsrse.js"></script>??
  • <head>??
  • <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">??
  • <title>Insert?title?here</title>??
  • <script?type="text/javascript">??
  • ????function?sendnews(){???
  • ????????var?new_content?=?dwr.util.getValue("newcontent");??
  • ????????myrevsrse.sendMes(new_content);??
  • ????}??
  • ??????
  • ????function?sendinfo(){???
  • ???????myrevsrse.noticeNewOrder(12);??
  • ????}????
  • </script>??
  • </head>??
  • <body>??
  • <input?type="text"?name="newcontent">??
  • <input?type?=?"button"?value="發消息"?onclick="sendnews()"/>???
  • <br?/>??
  • <input?type?=?"button"?value="send?2"?onclick="sendinfo()"/>??
  • <br?/>????
  • </body>??
  • ?同樣,這里的問題也是怎么實現點對點的信息推送,這兒只是實現了向所有的clent.html頁面推送信息,以后接著總結。。。。

    ?


    tomcat集群http://blog.csdn.net/lifetragedy/article/details/7712691

    ?

    轉載于:https://www.cnblogs.com/james1207/p/3341717.html

    總結

    以上是生活随笔為你收集整理的dwr消息推送和tomcat集群的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。