[java]代码库
package wyf;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dojox.cometd.Bayeux;
import dojox.cometd.Channel;
/**
* Project:AjaxCometChat <br>
* Module: <br>
* Description: <br>
* Version:1.0 <br>
* Date:2013-7-31 <br>
* Copyright (C) 2012 <br>
*
* @author:beijing_qi
*/
public class AjaxReceiveServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
ServletContext application=this.getServletContext();
Bayeux b=(Bayeux)application.getAttribute(Bayeux.DOJOX_COMETD_BAYEUX);
List<String> zxlb=(List<String>)application.getAttribute("zxlb");
if(null==zxlb){
zxlb=new ArrayList<String>();
}
String action=request.getParameter("action");
if(action!=null){
if(action.equals("nc")){
String nc=request.getParameter("nc");
if(zxlb.contains(nc)){
out.print("<#nccf#>");
}else{
zxlb.add(nc);
application.setAttribute("zxlb", zxlb);
out.print("<#ncok#>");
Channel c=b.getChannel("/Manage", true);
Map<String,Object> message=new HashMap<String,Object>();
String lbStr="";
for(String tempNc:zxlb){
lbStr=lbStr+tempNc+"<#>";
}
message.put("lbStr", lbStr);
message.put("pubStr", nc+"%u8fdb%u5165%u804a%u5929%u5ba4%uff01\n");
c.publish(b.newClient("server_user"), message, "new_server_message");
}
}else if(action.equals("tc")){
String nc=request.getParameter("nc");
zxlb.remove(nc);
out.print("<#tcok#>");
Channel c=b.getChannel("/Manage", true);
Map<String,Object> message=new HashMap<String,Object>();
String lbStr="";
for(String tempNc:zxlb){
lbStr=lbStr+tempNc+"<#>";
}
message.put("lbStr", lbStr);
message.put("pubStr", nc+"%u9000%u51fa%u804a%u5929%u5ba4%uff01\n");
c.publish(b.newClient("server_user"), message, "new_server_message");
}
}
}
}
[代码运行效果截图]
中级程序员
by: 中国人在美国 发表于:2013-08-01 05:22:26 顶(1) | 踩(0) 回复
沙发,顶一个
回复评论