项目:JavaWeb聊天室(问题汇总)

项目:JavaWeb聊天室(问题汇总)

项目需求:

建立一个网页聊天室

1.用户可以登录进来

2.用户进入聊天室之后可以互相发送消息

3.聊天室管理员有权限将普通用户踢下线

项目框架:

myeclipse建立基本的javaweb项目,采用基本的mvc三层架构:servlet,dao,service;

项目设计:

1.设计登录页面index.jsp,

index.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<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">&nbsp;</td>
            </tr>
            <tr>
                <td width="53" align="center" valign="top" class="word_dark">&nbsp;</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">&nbsp;</td>
                <td width="216" align="center" valign="top" class="word_dark">
                    <table width="100%" height="100%">
                        <tr>
                            <td>&nbsp;&nbsp;码:</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">&nbsp;</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>

 

 

2.设计主页面main.jsp,

 

<%@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",
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值