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

📄 chatdo.java

📁 一个bbs论坛系统
💻 JAVA
字号:
package com.lovo.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.lovo.po.PrivateChatPO;
import com.lovo.po.PublicChatDO;
import com.lovo.po.UserPO;

public class ChatDO extends HttpServlet{


	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("utf-8");
		ServletContext application=this.getServletContext();
		HttpSession session = request.getSession(true);

		
		String chat=request.getParameter("chat");
		/**判断私聊参数*/
		String isPrivate=request.getParameter("isPrivate");
		
		UserPO user1PO=(UserPO)session.getAttribute("user");
		String user1=user1PO.getName();
		
		/**要私聊的用户名*/
		String user2=(String)request.getParameter("user2");
		UserPO user2PO=new UserPO();
		user2PO.setName(user2);
		
		List<PublicChatDO> chatList=(List<PublicChatDO>)application.getAttribute("chatList");
		if(chatList==null){
			chatList=new ArrayList<PublicChatDO>();
		}
		if(isPrivate.equals("false")){
			PublicChatDO publicChat=new PublicChatDO();
			publicChat.setPublicChat(chat);
			publicChat.setSendUser(user1PO);
			chatList.add(publicChat);
			
			application.setAttribute("chatList", chatList);
			
		}else{
			PrivateChatPO privateChatPO = new PrivateChatPO();
			privateChatPO.setPrivateChat(chat);
			privateChatPO.setReceiveUser(user2PO);
			privateChatPO.setSendUser(user1PO);
			List<PrivateChatPO> privateList=(List<PrivateChatPO>)application.getAttribute("privateList");
			if(privateList==null){
				privateList=new ArrayList<PrivateChatPO>();
				application.setAttribute("privateList", privateList);
			}
			privateList.add(privateChatPO);

			
		}
		
	}

}

⌨️ 快捷键说明

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