一个用ajax实现聊天室

以前实现聊天必须每隔几秒钟来进行刷新页面保正数据同步,让人感觉太烦了!
这里用 ajax + servlet + sqlserver 实现聊天室功能! 

//JSP页面

//index

<%@ page contentType="text/html; charset=GBK" %>
<html>
  <head>
    <title>
      index
    </title>
    <link  href="css/web.css" style="text/css" rel="stylesheet"/>
  </head>
  <frameset rows="40,*">
    <frame id="top" noresize scrolling="no" frameborder="0" src="top.jsp">
     <frameset id="Middle" rows="*,130" frameborder="0">
       <frameset cols="160,*" frameborder="1">
         <frame id="left" scrolling="auto" src="Left.jsp" frameborder="0">
          <frame id="main" scrolling="auto" src="Main.jsp" frameborder="0">
          </frameset>
           <frame frameborder="1" id="bottom" scrolling="no" frameborder="0" src="Bottom.jsp">
      </frameset>
  </frameset>
</html>

//Buttom

<%@ page contentType="text/html; charset=GBK" %>
<html>
  <head>
    <title>
      Bottom
    </title>
    <script type=""  src="js/Bottom.js" language="javascript">

    </script>
  </head>
  <body bgcolor="#ffffff">
    <form method="post" action="Bottom.jsp" name="form1">
      <table width="722" height="124" border="0" style="border:black 1px solid" bordercolor="#CC9966" bgcolor="#CCFFCC">
        <tr>
          <td height="33">
            <select name="stFont" size="1">
              <option value="宋体" selected=true>宋体</option>
              <option value="黑体">黑体</option>
              <option value="隶书">隶书</option>
              <option value="Arial">Arial</option>
            </select>
            <select name="stColor" size="1">
              <OPTION style="COLOR: black" value="black" selected>■ black</OPTION>
              <OPTION style="COLOR: dimgray" value="dimGray">■ dimGray</OPTION>
              <OPTION style="COLOR: gray" value="gray">■ Gray</OPTION>
              <OPTION style="COLOR: darkgray" value="darkGray">■ darkGray</OPTION>
              <OPTION style="COLOR: silver" value="silver">■ silver</OPTION>
              <OPTION style="COLOR: lightgrey" value="lightgrey">■ LightGrey</OPTION>
              <OPTION style="COLOR: gainsboro" value="gainsboro">■ GainsBoro</OPTION>
              <OPTION style="COLOR: whitesmoke" value="whitesmoke">■ whitesmoke</OPTION>
              <OPTION style="COLOR: white" value="white">■ white</OPTION>
              <OPTION style="COLOR: rosybrown" value="RosyBrown">■ RosyBrown</OPTION>
              <OPTION style="COLOR: indianred" value="IndianRed">■ IndianRed</OPTION>
              <OPTION style="COLOR: brown" value="firebrick">■ brown</OPTION>
              <OPTION style="COLOR: firebrick" value="lightcoral">■ firebrick</OPTION>
              <OPTION style="COLOR: darkred" value="darkred">■ darkred</OPTION>
              <OPTION style="COLOR: snow" value="snow">■ snow</OPTION>
              <OPTION style="COLOR: tomato" value="tomato">■ tomato</OPTION>
              <OPTION style="COLOR: darksalmon" value="darksalmon">■ darksalmon</OPTION>
              <OPTION style="COLOR: orangered" value="orangered">■ orangered</OPTION>
              <OPTION style="COLOR: red" value="red">■ red</OPTION>
              <OPTION style="COLOR: lightsalmon" value="lightsalmon">■ lightsalmon</OPTION>
              <OPTION style="COLOR: seashell" value="seashell">■ seashell</OPTION>
              <OPTION style="COLOR: chocolate" value="chocolate">■ chocolate</OPTION>
              <OPTION style="COLOR: gold" value="gold">■ gold</OPTION>
              <OPTION style="COLOR: yellow" value="yellow">■ yellow</OPTION>
              <OPTION style="COLOR: olive" value="olive">■ olive</OPTION>
              <OPTION style="COLOR: greenyellow" value="greenyellow">■ greenyellow</OPTION>
              <OPTION style="COLOR: forestgreen" value="forestgreen">■ forestgreen</OPTION>
              <OPTION style="COLOR: limegreen" value="limegreen">■ limegreen</OPTION>
              <OPTION style="COLOR: darkgreen" value="darkgreen">■ darkgreen</OPTION>
              <OPTION style="COLOR: green" value="green">■ green</OPTION>
              <OPTION style="COLOR: lime" value="lime">■ lime</OPTION>
              <OPTION style="COLOR: seagreen" value="seagreen">■ seagreen</OPTION>
              <OPTION style="COLOR: springgreen" value="sienna">■ springgreen</OPTION>
              <OPTION style="COLOR: powderblue" value="springgreen">■ orangered</OPTION>
              <OPTION style="COLOR: lightblue" value="lightblue">■ lightblue</OPTION>
              <OPTION style="COLOR: skyblue" value="skyblue">■ skyblue</OPTION>
              <OPTION style="COLOR: steelblue" value="steelblue">■ steelblue</OPTION>
              <OPTION style="COLOR: aliceblue" value="aliceblue">■ aliceblue</OPTION>
              <OPTION style="COLOR: royalblue" value="royalblue">■ royalblue</OPTION>
              <OPTION style="COLOR: navy" value="navy">■ navy</OPTION>
              <OPTION style="COLOR: darkblue" value="darkblue">■ darkblue</OPTION>
              <OPTION value="middleblue">■ middleblue</OPTION>
              <OPTION style="COLOR: blue" value="blue">■ blue</OPTION>
              <OPTION style="COLOR: purple" value="purple">■ purple</OPTION>
              <OPTION style="COLOR: deeppink" value="deeppink">■ deeppink</OPTION>
              <OPTION style="COLOR: pink" value="pink">■ pink</OPTION>
              <OPTION style="COLOR: lightpink" value="lightpink">■ lightpink</OPTION>
            </select>
            <SELECT id="ddlFontSize" name="ddlFont"  style="MARGIN:-2px;WIDTH:60px">
              <OPTION value="1">1</OPTION>
              <OPTION value="2" selected>2</OPTION>
              <OPTION value="3">3</OPTION>
              <OPTION value="4">4</OPTION>
              <OPTION value="5">5</OPTION>
              <OPTION value="6">6</OPTION>
              <OPTION value="7">7</OPTION>
            </SELECT>
            <input name="chkPhone" type="checkbox" value="0"  >悄悄话
              <select name="ddlUser" Width="100px">
                <option value="0" selected=true>所有人</option>
              </select>
              <strong>说:</strong>
          </td>
        </tr>
            <tr>
              <td valign="top">
                <input  type="hidden" value="0" name="ReceiverId" id="ReceiverId"/>
                <textarea name="textarea" cols="60" rows="5"></textarea>
                <input name="btnSend" type="button" id="btnSend" style="width:100;height:70;" οnclick="getMessage();" value="发送">
              </td>
        </tr>
      </table>
  </form>
  </body>
</html>

//Left

<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
Left
</title>
<script type="text/javascript"  src="js/Left.js" language="javascript">

</script>
</head>
<body bgcolor="#ffffff" οnlοad="getInfo();">
<form method="post" action="Left.jsp">
  <table id="datatable" align="left" border="0" cellpadding="2" cellspacing="2" style="border:black 1px solid" bgcolor="#FFAFA">
    <tbody id="datatbody">

    </tbody>
  </table>
</form>
</body>
</html>
//Main

<%@page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>Main</title>
<script type="" src="js/Main.js" language="javascript">
</script>
</head>
<body bgcolor="#ffffff" οnlοad="getMessage();">
<div id="datadiv"></div>
</body>
</html>
//Login

<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
用户登录
</title>
</head>
<link  href="css/web.css" style="text/css" rel="stylesheet"/>
<body bgcolor="#ffffff" οnlοad="javascript:document.all.txtName.focus();">
<h3 align="center">
欢迎登录聊天室
</h3>
<form action="login" method="POST">

<table align="center" border="0" cellpadding="2" cellspacing="2" bgcolor="#FFFAFA" style="border:red 1px solid">
  <tr>
   <td>姓名:</td> <td><input  type="text" name="txtName"/></td>
  </tr>
  <tr>
    <td>密码:</td><td><input  type="password" name="txtPwd"/></td>
  </tr>
  <tr>
   <td></td> <td><input  type="submit" value="登录"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input  type="reset" value="取消"/></td>
  </tr>
</table>
</form>
</body>
</html>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值