package lee;
import java.util.*;
import java.io.*;
/**
* Description:
* <br/>网站: <a href="http://www.crazyjava.org">疯狂Java联盟</a>
* <br/>Copyright (C), 2001-2010, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class ChatService
{
//使用单例模式来设计ChatService
private static ChatService cs;
//使用Properties对象保存系统的所有用户
private Properties userList;
//使用LinkedList对象保存聊天信息
private LinkedList<String> chatMsg;
//构造器私有
private ChatService()
{
}
//通过静态方法返回唯一的ChatService对象
public static ChatService instance()
{
if (cs == null)
{
cs = new ChatService();
}
return cs;
}
//验证用户的登录
public boolean validLogin(String user , String pass)
throws IOException
{
//根据用户名获取密码
String loadPass = loadUser().getProperty(user);
//登录成功
if (loadPass != null
&& loadPass.equals(pass))
{
return true;
}
return false;
}
//新注册用户
public boolean addUser(String name , String pass)
throws Exception
{
//当userList为null,初始化userList对象
if (userList == null)
{
userList = loadUser();
}
//如果userList已经所需注册的用户
if (userList.containsKey(name))
{
throw new Exception("用户名已经存在,请重新选择用户名");
}
userList.setProperty(name , pass);
saveUserList();
return true;
}
//获取系统中所有聊天信息
public String getMsg()
{
//如果chatMsg对象为null,表明不曾开始聊天
if (chatMsg == null)
{
chatMsg = new LinkedList<String>();
return "";
}
StringBuilder result = new StringBuilder("");
//将chatMsg中所有聊天信息拼接起来。
for (String tmp : chatMsg)
{
result.append(tmp + "\n");
}
return result.toString();
}
//用户发言,添加聊天信息
public void addMsg(String user , String msg)
{
///如果chatMsg对象为null,初始化chatMsg对象
if (chatMsg == null)
{
chatMsg = new LinkedList<String>();
}
//最多保存40条聊天信息,当超过40条之后,将前面聊天信息删除
if (chatMsg.size() > 40)
{
chatMsg.removeFirst();
}
//添加新的聊天信息
chatMsg.add(user + "说:" + msg);
}
//------------下面是系统的工具方法--------------
//读取系统用户信息
private Properties loadUser() throws IOException
{
if (userList == null)
{
//加载userFile.properties文件
File f = new File("userFile.properties");
//如果文件不存在,新建该文件
if (!f.exists())
{
f.createNewFile();
}
//新建Properties文件
userList = new Properties();
//读取userFile.properties文件里的用户信息
userList.load(new FileInputStream(f));
}
return userList;
}
//保存系统所有用户
private boolean saveUserList() throws IOException
{
if (userList == null)
{
return false;
}
//将userList信息保存到Properties文件中
userList.store(new FileOutputStream("userFile.properties"),
"Users Info List");
return true;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
疯狂Ajax讲义随书光盘(1-9)
共440个文件
html:262个
jsp:40个
xml:31个
5星 · 超过95%的资源 需积分: 9 40 下载量 130 浏览量
2009-10-16
20:55:36
上传
评论 3
收藏 1.8MB RAR 举报
温馨提示
疯狂Ajax讲义随书光盘(1-9) 全书主要分为三个部分。第一部分介绍了XHTML、CSS、JavaScript和DOM编程等内容。第二部分详细介绍了Prototype、 jQuery、DWR、AjaxTags等四个最常用的Ajax框架的用法,并针对每个框架提供了一个实用案例。这两个部分是笔者在“疯狂Java实训营”的培训讲义,是本书的重点部分。第三部分则提供了2个综合性案例:Blog系统和电子拍卖系统,让读者将前面所学真正应用到实际项目中。
资源推荐
资源详情
资源评论
收起资源包目录
疯狂Ajax讲义随书光盘(1-9) (440个子文件)
ChatService.class 3KB
ChatService.class 3KB
ChatService.class 3KB
ChatService.class 3KB
ChatService.class 3KB
ChatService.class 3KB
DOMGenerate.class 3KB
DOMParserTest.class 3KB
LoginServlet.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
RegServlet.class 2KB
RegServlet.class 2KB
RegServlet.class 2KB
RegServlet.class 2KB
RegServlet.class 2KB
RegServlet.class 2KB
ChatServlet.class 2KB
ChatServlet.class 2KB
ChatServlet.class 2KB
ChatServlet.class 2KB
ChatServlet.class 2KB
ChatServlet.class 2KB
.classpath 362B
.classpath 340B
.classpath 340B
outer.css 229B
css.css 131B
data 16B
data 15B
xhtml1-frameset.dtd 32KB
xhtml1-transitional.dtd 31KB
xhtml1-strict.dtd 25KB
car130.gif 2KB
indicator.gif 2KB
indicator.gif 2KB
indicator.gif 2KB
indicator.gif 2KB
indicator.gif 2KB
indicator.gif 2KB
logo.gif 1KB
wjc.gif 1KB
plus.gif 205B
minus.gif 199B
passage.gif 144B
cascadeMune.htm 2KB
qs.htm 100B
menu.html 5KB
chat.html 3KB
chat.html 3KB
chat.html 3KB
chat.html 3KB
first.html 3KB
tree.html 3KB
first.html 3KB
first.html 2KB
first.html 2KB
String.html 2KB
first.html 2KB
index.html 2KB
Form.html 2KB
first.html 2KB
wind.html 2KB
scriptTrigger.html 2KB
index.html 2KB
Form.Element.html 2KB
domBind.html 2KB
first.html 2KB
elementBind.html 2KB
JSONTest.html 2KB
first.html 2KB
first.html 2KB
getForm.html 2KB
editable_table.html 2KB
position.html 2KB
index.html 2KB
Function.html 2KB
stopPropagation.html 2KB
changeValue.html 2KB
table.html 2KB
addEventListener.html 1KB
AccessByNodeRelation.html 1KB
list.html 1KB
removeTable.html 1KB
font.html 1KB
status2.html 1KB
fireEvent2.html 1KB
dispatchEvent.html 1KB
Hash.html 1KB
AccessSelect.html 1KB
$$()Test.html 1KB
stopPropagation2.html 1KB
Class.html 1KB
bg.html 1KB
objectBind.html 1KB
insert.html 1KB
inline.html 1KB
共 440 条
- 1
- 2
- 3
- 4
- 5
资源评论
- ytczlj2012-09-04能给全部的就好了
- 普通网友2012-07-31怎么只有1-9章的代码
- wangwanfeng5122013-08-07我擦,这是第二版的,我要的是第三版,也不说明下I啊!5分啊~~~~!!!!
- tyok19862013-11-04不错的资料,配合原书使用。要是有书能打包一起下载就好了
- sayyoume82202022013-01-16要是能给全就更好了,不过也非常感谢
totly2009
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功