Chat.java
package customers;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
public class Chat extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{response.setContentType("text/html;charset=gb2312");
String thisMySpeaking=new String(request.getParameter("txtword")
.getBytes("ISO-8859-1"),"GB2312");
//处理Java对中文处理的一些问题,如果不用这两句,你可能会看到乱码
String thisTargetUserId=request.getParameter("seluser");
String thisColor=request.getParameter("selcolor");
String thisFace=request.getParameter("selface");
String selRe1=request.getParameter("selre1");
String selRe2=request.getParameter("selre2");
String thisRadprivate=request.getParameter("radprivate");
if (thisRadprivate==null) thisRadprivate=new String("no");
//接收表单的各项录入数据
HttpSession session=request.getSession(true);
oneUser thisUser=(oneUser)session.getAttribute("thisUser");
String thisSourceUserId=thisUser.getUserId();
String thisSourceUserName=thisUser.getUserName();
int intChatroom=Integer.parseInt(thisUser.getUserPosion());
//从session中取当前用户的相关信息
ServletContext application=getServletContext();
ChatRoom thischatroom=(ChatRoom)application.getAttribute("thischatroom");
int retimeuser=Integer.parseInt(selRe2);
int retimechat=Integer.parseInt(selRe1);
thisUser.setRetimeUser(retimeuser,intChatroom);
thisUser.setRetimeChat(retimechat,intChatroom);
//按表单内容重新设置两个刷新时间
String thisTargetUserName=thischatroom.returnUserName
(intChatroom,thisTargetUserId);
thischatroom.addSpeaking(thisMySpeaking,thisSourceUserId,
thisTargetUserId,
thisSourceUserName,thisTargetUserName,thisFace,thisColor,
thisRadprivate,intChatroom);
//增加发言内容
getServletConfig().getServletContext().getRequestDispatcher
("/jsp/mychat.jsp").forward(request,response);
//转向mychat.jsp显示
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
|