?? getprivatechatdo.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.UserPO;
public class GetPrivateChatDO extends HttpServlet{
private static final long serialVersionUID = 7652108736999314237L;
protected void doGet(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);
PrintWriter out = response.getWriter();
List<PrivateChatPO> privateList=(List<PrivateChatPO>)application.getAttribute("privateList");
if(privateList==null){
privateList=new ArrayList<PrivateChatPO>();
application.setAttribute("privateList", privateList);
}
String sendContent="";
UserPO currentUser=(UserPO)session.getAttribute("user");
for(int i=0;i<privateList.size();i++){
UserPO user1PO=((PrivateChatPO)privateList.get(i)).getSendUser();
UserPO user2PO=((PrivateChatPO)privateList.get(i)).getReceiveUser();
String privateChat=((PrivateChatPO)privateList.get(i)).getPrivateChat();
if(currentUser.getName().equals(user1PO.getName())){
sendContent=sendContent+"你對"+user2PO.getName()+"說: "+privateChat+"<br>";
}
if(currentUser.getName().equals(user2PO.getName())){
sendContent=sendContent+user1PO.getName()+"對你說: "+privateChat+"<br>";
}
}
out.print(sendContent);
return;
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -