当前位置: 代码迷 >> Java Web开发 >> 关于聊天室主界面的有关问题
  详细解决方案

关于聊天室主界面的有关问题

热度:216   发布时间:2016-04-16 21:52:58.0
关于聊天室主界面的问题
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="safe.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>聊天室</title>
<link href="CSS/style.css" rel="stylesheet">
<script type="text/javascript" src="${ pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<script type="text/javascript">
var sysBBS = "<span style='font-size:14px; line-height:30px;'>欢迎光临XX聊天室,请遵守聊天室规则,不要使用不文明用语。</span><br><span style='line-height:22px;'>";var sysBBS = "<span style='font-size:14px; line-height:30px;'>欢迎光临XX聊天室,请遵守聊天室规则,不要使用不文明用语。</span><br><span style='line-height:22px;'>";
window.setInterval("showContent();",1000);
window.setInterval("showOnLine();",10000);
window.setInterval("check();",1000);
// Jquery:JS框架.
// 相当于window.onload
$(function(){
showOnLine();
showContent();
check();
});
function check(){
$.post("${pageContext.request.contextPath}/user?method=check",function(data){
if(data == 1){
// 提示用户下线了
alert("用户已经被踢下线了!");
// 回到登录页面!
window.location = "index.jsp";
}
});
}
// 显示在线人员列表
function showOnLine(){
// 异步发送请求 获取在线人员列表
// Jquery发送异步请求
$.post("${pageContext.request.contextPath}/online.jsp?"+new Date().getTime(),function(data){
// $("#online") == document.getElementById("online");
$("#online").html(data);
});
}
// 显示聊天的内容
function showContent(){
$.post("${pageContext.request.contextPath}/user?"+new Date().getTime(),{'method':'getMessage'},function(data){
$("#content").html(sysBBS+data);
});
}
function set(selectPerson){ //自动添加聊天对象
if(selectPerson != "${existUser.username}"){
form1.to.value=selectPerson;
}else{
alert("请重新选择聊天对象!");
}
}
function send(){
if(form1.to.value==""){
alert("请选择聊天对象!");
return false;
}
if(form1.content.value==""){
alert("发送信息不可以为空!");
form1.content.focus();
return false;
}
// $("#form1").serialize():让表单中所有的元素都提交.
// jquery提交数据.{id:1,name:aa,age:25}

$.post("${pageContext.request.contextPath}/user?"+new Date().getTime(),$("#form1").serialize(),function(data){
$("#content").html(sysBBS+data+"</span>");
$("input[name='content']").val("");

});
}
function exit(){
alert("欢迎您下次光临!");
window.location.href="${pageContext.request.contextPath}/user?method=exit";
}
function checkScrollScreen(){
if(!$("#scrollScreen").attr("checked")){
     $("#content").css("overflow","scroll");
    }else{
     $("#content").css("overflow","hidden");
        //当聊天信息超过一屏时,设置最先发送的聊天信息不显示
        alert($("#content").height());
        $("#content").scrollTop($("#content").height()*2);
    }
    setTimeout('checkScrollScreen()',500);
}
</script>
</head>
<body>
<table width="778" height="150" border="0" align="center"
cellpadding="0" cellspacing="0" background="images/top.jpg">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<table width="778" height="276" border="0" align="center"
cellpadding="0" cellspacing="0">
<tr>
<td width="165" valign="top" bgcolor="#f6fded" id="online" style="padding:5px">在线人员列表</td>
<td width="613" height="200px" valign="top"
background="images/main_bj.jpg" bgcolor="#FFFFFF"
style="padding:5px; ">
<div style="height:290px; overflow:hidden" id="content">聊天内容</div></td>
</tr>
</table>
<table width="778" height="95" border="0" align="center"
cellpadding="0" cellspacing="0" bordercolor="#D6D3CE"
background="images/bottom.jpg">

<form action="" id="form1" name="form1" method="post">
<input type="hidden" name="method" value="sendMessage"/>
<tr>
<td height="30" align="left">&nbsp;</td>
<td height="37" align="left">
<input name="from" type="hidden" value="${existUser.username}">[${existUser.username} ]对 
<input name="to" type="text" value="" size="25" readonly="readonly"> 表情 
<select name="face" class="wenbenkuang">
<option value="无表情的">无表情的</option>
<option value="微笑着" selected>微笑着</option>
</select> 说:</td>
<td width="189" align="left">&nbsp;&nbsp;字体颜色: <select
  相关解决方案