${ msg }表示什么意思呢???
index.jsp怎么跳转到main.jsp呢???
index.jsp
<html >
<title>聊天室</title>
<link href="CSS/style.css" rel="stylesheet">
<script type="text/javascript">
function check(){
if(document.getElementById("form1").username.value==""){
alert("请输入用户名!");
document.getElementById("form1").username.focus();
return false;
}
if(document.getElementById("form1").password.value==""){
alert("请输入密码名!");
document.getElementById("form1").password.focus();
return false;
}
}
</script>
<body>
<br>
<center><h3 style="color:red;">${ msg }</h3></center>
<form id="form1" name="form1" method="post" action="${pageContext.request.contextPath }/user" onSubmit="return check()">
<input type="hidden" name="method" value="login">
<table width="371" height="230" border="0" align="center" cellpadding="0" cellspacing="0" background="images/login.jpg">
<tr>
<td height="120" colspan="3" class="word_dark"> </td>
</tr>
<tr>
<td width="53" align="center" valign="top" class="word_dark"> </td>
<td width="216" align="center" valign="top" class="word_dark">
<table width="100%" height="100%">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" class="login"></td>
</tr>
</table>
</td>
<td width="94" valign="top" class="word_dark"></td>
</tr>
<tr>
<td width="53" align="center" valign="top" class="word_dark"> </td>
<td width="216" align="center" valign="top" class="word_dark">
<table width="100%" height="100%">
<tr>
<td>密 码:</td>
<td><input type="password" name="password" class="login"></td>
</tr>
</table>
</td>
<td width="94" valign="top" class="word_dark"></td>
</tr>
<tr>
<td width="53" align="center" valign="top" class="word_dark"> </td>
<td width="216" align="center" valign="top" class="word_dark">
<input name="Submit" type="submit" class="btn_bg" value="进 入">
</td>
<td width="94" valign="top" class="word_dark">
</td>
</tr>
</table>
</form>
</body>
</html>
main
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="safe.jsp"%>
<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;'>欢迎光临心之语聊天室,请遵守聊天室规则,不要使用不文明用语。</span><br><span style='line-height:22px;'>";var sysBBS = "<span style='font-size:14px; line-height:30px;'>欢迎光临心之语聊天室,请遵守聊天室规则,不要使用不文明用语。</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>");
});
}
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> </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"> </td>
<td height="37" align="left">
<input name="from" type="hidden" value="${existUser.username}">[${existUser.username} ]对
<input name="to" type="text" value="" size="35" readonly="readonly"> 表情
<select name="face" class="wenbenkuang">
<option value="无精打采的">无精打采的</option>
</select> 说:</td>
<td width="189" align="left"> 字体颜色: <select
name="color" size="1" class="wenbenkuang" id="select">
<option selected>默认颜色</option>
<option style="color:#999999" value="999999">烟雨蒙蒙</option>
</select>
</td>
<td width="19" align="left"><input name="scrollScreen"
type="checkbox" class="noborder" id="scrollScreen"
onClick="checkScrollScreen()" value="1" checked>
</td>
</tr>
<tr>
<td width="21" height="30" align="left"> </td>
<td width="549" align="left">
<input name="content" type="text" size="70"
onKeyDown="if(event.keyCode==13 && event.ctrlKey){send();}">
<input name="Submit2" type="button" class="btn_grey" value="发送"
onClick="send()">
</td>
<td align="right"><input name="button_exit" type="button"
class="btn_grey" value="退出聊天室" onClick="exit()">
</td>
<td align="center"> </td>
</tr>
<tr>
<td height="30" align="left"> </td>
<td align="center"> </td>
</tr>
</form>
</table>
</body>
</html>