网上在线聊天系统main.jsp

来源:互联网 发布:网络暴力的事件 编辑:程序博客网 时间:2024/04/30 04:12

<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import="java.sql.*,java.util.*"%>
<jsp:useBean scope="page" id="Ex" class="com.chat.Execute_DB" />
<%
 //设置编码格式
 request.setCharacterEncoding("gb2312");
 //获取登录用户名和聊天室名,并保存到session对象中
 String str_UserName = request.getParameter("UserName");
 String str_ChatRoom = request.getParameter("ChatRoom");
 session.setAttribute("UserName",str_UserName);
 session.setAttribute("ChatRoom",str_ChatRoom);
 //更新用户活动情况
 java.util.Date NowDate = new java.util.Date();
 long l_ChatTime = NowDate.getTime();
 String strSql = "select ID from userlist where UserName like '"+str_UserName+"'";
 //out.println(strSql);
 ResultSet rs = Ex.exeSqlQuery(strSql);
 if(rs.next())
 {
  //用户换房间的情况  
  strSql = "update userlist set CharTime = '"+l_ChatTime+"',ChatRoom = '"+str_ChatRoom+"' where UserName like '"+str_UserName+"'";
  Ex.exeSql(strSql);
 }
 else
 {
  //用户刚登录的情况
  strSql = "insert into userlist (ChatRoom,UserName,ChatTime) values ('"+str_ChatRoom+"','"+str_UserName+"','"+l_ChatTime+"')";
  Ex.exeSql(strSql);
 }
 rs.close();
 //更新用户登录时间
 strSql = "update users set LoginTime = '"+l_ChatTime+"' where UserName like '"+str_UserName+"'";
 Ex.exeSql(strSql);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title>欢迎光临本聊天室</title>
 </head>
 <frameset rows="*" cols="130,*" border="1" framespacing="1" bordercolor="#FF0000">
  <frame name="leftFrame" scrolling="no" noresize src="left.jsp">
  <frameset rows="*,130" border="1" framespacing="1" cols="*" bordercolor="#FF0000">
   <frame name="topFrame" scrolling="yes" src="display.jsp">
   <frame name="mainFrame" src="send.jsp">
  </frameset>
 </frameset>
 <noframes>
 <body>
  <h1 align="center">
  <font color="#FF0000">您的浏览器不知道框架,所以不能看到内容。</font>
  </h1>
 </body>
 </noframes>
</html>