JSP及Servlet实现Web聊天室(二)-个人联系Day9

本文档详细介绍了如何使用JSP和Servlet实现一个Web聊天室,包括登录功能(利用Cookie存储密码)、聊天室监听、界面设计(整合CSS)以及Servlet处理发送和查看消息。还涉及到过滤器CodeFilter和监听器OnlineListener的实现,所有代码示例和登录/聊天室效果展示。开发环境为Netbeans,服务器为GlassFish4.1。
摘要由CSDN通过智能技术生成
源代码(所有界面已经整合CSS)
登录界面源代码链接:点我直达
聊天室监听功能JSP部分代码 header.jsp
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gb2312" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <meta http-equiv="Content-Type" content="text/html;charset=gb2312">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <style type="text/css">
        body{
   
	margin: 0;
	padding: 0;
	font-family: sans-serif;
}
.listen{
   
	text-align:center;
	width: 100%;
        position: absolute;
	top: 40%;
	left: 50%;
	transform: translate(-50%, -50%);
	margin: 0;
	padding: 0;
	display: block;
	background:#211B1B;
	font-size: 15px;
        font-weight: 599;
        text-align: center;
	color: white;
        letter-spacing: 2px;
	
}
    </style>

  </head>
  
  <body topmargin="0" leftmargin="0" rightmargin="0">
     <form action="">
                 <div class ="listen">欢迎<%=(String)request.getSession().getAttribute("nameSession") %>访问!当前在线人数为<%=application.getAttribute("peopleOnline")%></div>                       
             </table>
           </form>
  </body>
</html>
聊天室左侧没啥用的框架 left.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'test.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="content-type" content="text/html; charset=gb2312">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
 <style type="text/css">
        *
        {
   
            margin: 0;
            padding: 0;
        }
        body
        {
   
            font-size: 10px;
            padding: 10px;
        }
        .menu
        {
   
            width: 200px;
			margin: 0;
			background-color: white;
			border-radius: 20px;
			box-shadow: 0 5px 10px 0px gray;
        }
        .menu h3
        {
   
			text-align: center;
			height: 60px;
			margin-top:30px;
			padding-top: 20px;
			font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", "serif";
			font-size:20px;
			border-bottom: 2px solid lightgray;
        }
        .menu p
        {
   
			margin-top:10px;
			padding-top:10px;
			text-align: center;
			font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", "serif";
			font-size:15px;
			
		

        }
        .changecolor{
   background-color:gray;}
	    a{
    text-decoration:</
  • 7
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值