当前位置: 网学 > 网页素材 > AJAX代码 > 正文

用AJAX+J2EE实现一个网上会议室系统

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: Admin 发布时间: 09/05/30
止某个会议室

  * @param name 会议室ID

  * @return

  */

  public static boolean close(String name)

  {

  ChatService chatRoom=ChatService.get(name);

  if(chatRoom!=null)

  {

  chatRoom.stop();

  service.remove(name);

  }

  return true;

  }

  /**

  * 获得一个会议室信息

  * @param name 会议室ID

  * @return

  */

  public static ChatService get(String name)

  {

  if(service.containsKey(name))return (ChatService)service.get(name);

  else return null;

  }

  public void run() {

  // TODO Auto-generated method stub

  //this.thread=Thread.currentThread();

  while(!isStop)

  {

  //System.out.println("开始监控一个会议室!"+this.title);

  this.flash();

  try{

  Thread.sleep(5000);

  }

  catch(Exception e)

  {

  e.printStackTrace();

  }

  }

  //System.out.println("结束!");

  }

  public void stop()

  {

  this.flashAll();

  isStop=true;

  }

  //会议室中有人发言

  public boolean talk(Chat chat)

  {

  boolean ret=false;

  if(canTalk(chat.getSender()))

  {

  this.msgs.add(chat);

  ret=true;

  }

  return ret;

  }

  public boolean exit(ChatUser user)

  {

  talk(geneSystemMsg(user.getUserName()+"退出了会议室!"));

  return this.users.remove(user);

  }

  }

  //刷新信息,保存会议信息

  public void flash()

  {

  flashChatMsg();

  flashChatUser();

  }

  }

  2、MVC处理部分的Action代码

  在EasyJF的会议系统中,由于使用EasyJWeb作为MVC框架,因此处理Ajax比较简单,下面是会议室系统的核心Action主要代码。

  package com.easyjf.chat.action;

  public class ChatAction extends AbstractCmdAction {

  private ChatService chatRoom;

  public Object doBefore(WebForm form, Module module) {

  // TODO Auto-generated method stub

  if(chatRoom==null)chatRoom=ChatService.get((String)form.get("cid"));

  return super.doBefore(form, module);

  }

  public Page doInit(WebForm form, Module module) {

  // TODO Auto-generated method stub

  return doMain(form,module);

  }

  //用户登录进入会议室

  public Page doMain(WebForm form, Module module) {

  if(chatRoom!=null){

  ChatUser user=getChatUser();

  if(!chatRoom.join(user))form.addResult("msg","不能加入房间,可能是权限不够!");

  form.addResult("chatRoom",chatRoom);

  form.addResult("user",user);

  }

  else

  {

  form.addResult("msg","会议未启动或者会议室不存在!");

  }

  return module.findPage("main");

  }

  //处理用户发言信息

  public Page doSend(WebForm form, Module module) {

  if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误

  Chat chat=(Chat)form.toPo(Chat.class);

  chat.setCid(chatRoom.geneId());

  chatRoom.talk(chat);

  return doRecive(form,module);

  }

  //用户接收发言信息

  public Page doRecive(WebForm form, Module module) {

  if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误

  String lastReadId=CommUtil.null2String(form.get("lastReadId"));

  //System.out.println(lastReadId);

  form.addResult("list", chatRoom.getNewestMsg(getChatUser(),lastReadId));

  return module.findPage("msgList");

  }

  //用户刷新会议状态信息

  public Page doLoadConfig(WebForm form, Module module) {

  if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误

  form.addResult("userList", chatRoom.getUsers());

  form.addResult("talkerList", chatRoom.getTalkers());

  return module.findPage("config");

  }

  //用户退出

  public Page doExit(WebForm form, Module module) {

  if(chatRoom==null)return new Page("err","/err.html","t

网学推荐

免费论文

原创论文

设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号