⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendmessage.java

📁 开始学习dwr 聊天程序使用dwr的推模式
💻 JAVA
字号:
package com.lhq;
/** 
 * @author 邓健 dengjian1985@163.com 
 * @version 创建时间:Mar 18, 2009 4:18:49 PM 
 * 类说明 
 */
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.directwebremoting.ScriptBuffer;
import org.directwebremoting.ScriptSession;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.proxy.dwr.Util;

public class SendMessage {
 public void addMessage(String message)
 {
String s = "我对你说:"+message;
  messages.add(s);
System.out.println(s);
  
//	 WebContext wctx = WebContextFactory.get();
//     String currentPage = wctx.getCurrentPage();
//
//     ScriptBuffer script = new ScriptBuffer();
//     script.appendScript("receiveMessages(")
//           .appendData(messages)
//           .appendScript(");");
//
//     // Loop over all the users on the current page
//     Collection pages = wctx.getScriptSessionsByPage(currentPage);
//     for (Iterator it = pages.iterator(); it.hasNext();)
//     {
//         ScriptSession otherSession = (ScriptSession) it.next();
//         otherSession.addScript(script);
//     }
//  
  WebContext wctx = WebContextFactory.get();
  String currentPage = wctx.getCurrentPage();

  // Clear the input box in the browser that kicked off this page only
  Util utilThis = new Util(wctx.getScriptSession());
  utilThis.setValue("text", "");

  // For all the browsers on the current page:
  Collection sessions = wctx.getScriptSessionsByPage(currentPage);
  Util utilAll = new Util(sessions);

  // Clear the list and add in the new set of messages
  utilAll.removeAllOptions("chatlog");
  utilAll.addOptions("chatlog", messages, "text");
  
 }
 private List<String> messages=new LinkedList<String>();
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -