?? chatdo.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 + -