• 大小: 9.41MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-16
  • 语言: Java
  • 标签: JAVA  聊天室  

资源简介

基于JAVA的B/S聊天室,或者访问 http://121.40.59.28:8080/ChatRoom/jsp/out/login.jsp

资源截图

代码片段和文件信息

package com.tute.chatroom.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONobject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tute.chatroom.pojo.Message;
import com.tute.chatroom.pojo.UserList;
import com.tute.chatroom.service.ChatService;
import com.tute.chatroom.util.OtherUtil;
import com.tute.chatroom.util.RequestUtil;

@Controller(“chatController“)
@RequestMapping(“jsp/main“)
public class ChatController {

private ChatService chatService;

public ChatService getChatService() {
return chatService;
}
@Resource(name=“chatService“)
public void setChatService(ChatService chatService) {
this.chatService = chatService;
}

/**
 * 用户发送消息的方法,前台每1.5秒执行一次
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping(value=“/sendmessage“method={RequestMethod.POST})
@ResponseBody
public List saveDialog(HttpServletRequest request) throws Exception{
String msg = new String(RequestUtil.readRequest(request)
.getBytes(“iso-8859-1“)“UTF-8“);
JSONobject json = JSONobject.fromobject(msg);
String message = json.getString(“message“);
String speaker = (String) request.getSession().getAttribute(“user“);
if(!“flush“.equals(message)){
String face = json.getString(“face“);
String noname = json.getString(“noname“);
OtherUtil.saveFile(speaker+“ “+face+“ 说: “+message+“\n“);
if(“checked“.equals(noname)){
speaker = OtherUtil.getNoName(request);
}
chatService.addHistoryDialog(messagespeakerface);
}
return chatService.getMessages();
}

/**
 * 用户离开时的处理方法
 * @param request
 * @throws Exception
 */
@RequestMapping(value=“/leave“method={RequestMethod.POST})
@ResponseBody
public void leave(HttpServletRequest request) throws Exception{
String username = (String) request.getSession().getAttribute(“user“);
String noname = (String) request.getSession().getAttribute(“noname“);
request.getSession().removeAttribute(“user“);
UserList.getInstance().removeUser(username);
UserList.getInstance().removeNoName(noname);
Message message = new Message();
message.setSpeaker(“系统管理员“);
message.setContent(“用户  “+username+“  已下线“);
chatService.addHistoryDialog(message.getContent() message.getSpeaker() ““);

}

@RequestMapping(value=“/countuser“method={RequestMethod.POST})
@ResponseBody
public List getUserList(HttpServletRequest request){
return chatService.getUserList();
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2618  2015-02-07 15:04  ChatRoom\.classpath

     文件        297  2015-01-05 20:59  ChatRoom\.mymetadata

     文件       1751  2015-01-07 14:03  ChatRoom\.project

     文件        500  2015-01-05 20:59  ChatRoom\.settings\.jsdtscope

     文件        888  2015-02-08 13:31  ChatRoom\.settings\org.eclipse.core.resources.prefs

     文件        395  2015-01-05 20:59  ChatRoom\.settings\org.eclipse.jdt.core.prefs

     文件        462  2015-01-05 20:59  ChatRoom\.settings\org.eclipse.wst.common.component

     文件        252  2015-01-05 20:59  ChatRoom\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2015-01-05 20:59  ChatRoom\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2015-01-05 20:59  ChatRoom\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件        641  2015-02-05 15:35  ChatRoom\src\chat-mapping.xml

     文件       2906  2015-02-07 22:20  ChatRoom\src\com\tute\chatroom\controller\ChatController.java

     文件       4900  2015-02-08 16:21  ChatRoom\src\com\tute\chatroom\controller\UserController.java

     文件        207  2015-02-04 17:50  ChatRoom\src\com\tute\chatroom\dao\IChatDao.java

     文件       1405  2015-02-04 22:46  ChatRoom\src\com\tute\chatroom\dao\impl\baseDao.java

     文件       1109  2015-02-06 20:06  ChatRoom\src\com\tute\chatroom\dao\impl\ChatDao.java

     文件       1472  2015-02-08 00:01  ChatRoom\src\com\tute\chatroom\dao\impl\UserDao.java

     文件        306  2015-02-08 00:00  ChatRoom\src\com\tute\chatroom\dao\IUserDao.java

     文件       1031  2015-02-07 20:32  ChatRoom\src\com\tute\chatroom\intercepter\MainFilter.java

     文件        742  2015-02-05 21:31  ChatRoom\src\com\tute\chatroom\intercepter\UserIntercepter.java

     文件        717  2015-02-05 15:34  ChatRoom\src\com\tute\chatroom\pojo\Message.java

     文件        706  2015-02-08 13:09  ChatRoom\src\com\tute\chatroom\pojo\User.java

     文件       1160  2015-02-06 23:06  ChatRoom\src\com\tute\chatroom\pojo\UserList.java

     文件       1403  2015-02-05 19:33  ChatRoom\src\com\tute\chatroom\service\ChatService.java

     文件       3578  2015-02-08 16:47  ChatRoom\src\com\tute\chatroom\service\UserService.java

     文件        810  2015-02-03 21:59  ChatRoom\src\com\tute\chatroom\util\DBUtil.java

     文件       2010  2015-02-08 13:36  ChatRoom\src\com\tute\chatroom\util\MailUtil.java

     文件       4027  2015-02-07 21:11  ChatRoom\src\com\tute\chatroom\util\OtherUtil.java

     文件        705  2015-02-06 20:06  ChatRoom\src\com\tute\chatroom\util\RequestUtil.java

     文件       1360  2015-02-03 01:48  ChatRoom\src\com\tute\chatroom\util\SafeCode.java

............此处省略122个文件信息

评论

共有 条评论