【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《用jsp代码编写的网络聊天室程序》,欢迎阅读!
<%@ page contentType="text/html;charset=GBK" import="java.util.*"%>
带自动刷新的简易聊天室 <% if (request.getProtocol().compareTo("HTTP/1.0") == 0) response.setHeader("Pragma", "no-cache"); else if (request.getProtocol().compareTo("HTTP/1.1") == 0) response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", -1); %>
当前时间: <%
response.setHeader("Refresh","30");
request.setCharacterEncoding("GBK");
Date d=new Date();
out.println(""+ d.toLocaleString());
String userName = (String)session.getAttribute("userName"); if (userName == null ) userName="Guest"; String chat = request.getParameter("mychat"); String chats = (String)application.getAttribute("chat"); if (chat!=null){ d=new Date(); chat=userName + "(" + d.toLocaleString() + "):" + chat; if (chats==null) chats=chat; else chats = chats + "
" + chat; }
if (chats!=null){ application.setAttribute("chat", chats); %>
border="2" width="400" bordercolorlight="#FFFFFF" bordercolordark="#000000" cellspacing="0" cellpadding="0">
简易聊天室 |
<%= application.getAttribute("chat")%> |
<%}%>
本文来源:https://www.wddqxz.cn/afadee2f15fc700abb68a98271fe910ef12dae94.html