日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Web小应用---网页聊天室

發布時間:2023/12/18 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Web小应用---网页聊天室 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ?應用解析:當不同IP的用戶登錄掛載在服務器上的網頁聊天室時,就可以即時得進行像QQ一樣的文字聊天,進行即時通信。

? ? ?

? ? ? 代碼:

login.jsp

<%@ page language="java" contentType="text/html;charset=gb2312" %> <html> <body style=background-color:green > <marquee behavior="scroll" direction="right"><font color="black">歡迎光臨!</font></marquee> <h1 align="center">歡迎進入登錄室</h1> <hr color="red" /> <script type="text/javascript"> function denglu(){ if(document.getElementsByName("username")[0].value==""){ alert("賬號不能為空!"); document.getElementsByName("username")[0].focus();return false;} if(document.getElementsByName("password")[0].value==""){ alert("密碼不能為空!"); document.getElementsByName("password")[0].focus();return false;} } </script> <form name="form1" method="post" action="main.jsp"> <p align="center"> 用戶名:<input type="text" name="username" > <br/> 密 碼: <input type="password" name="password"> <br/> <input type="submit" value="登錄" οnclick="return denglu();" /> <input type="reset" value="重置"> </p> </form></body> </html>
main.jsp

<%@ page language="java" contentType="text/html;charset=utf-8" %> <html> <head></head><frameset rows="90%,10%"><frame src="display.jsp" name="top"></frame><frame src="sponse.jsp" name="bottom"></frame></frameset> <%request.setCharacterEncoding("gbk");String username=(String)request.getParameter("username");session.setAttribute("username", username);%> </html>
sponse.jsp

<%@ page language="java" contentType="text/html;charset=gb2312" %> <html> <head> <script type="text/javascript">function sendMsg(){if(form3.message.value==""){alert("不能發送空消息!");return false;}}</script> </head> <body style=background-color:green ><form name="form3" method="post" action="display.jsp" target="top" οnsubmit="return sendMsg()" > <p align="center"> <input type="text" name="message" style="width:600px"> <input type="submit" value="我要留言" > <input type="reset" value="清除"> </p> </form></body> </html>
display.jsp

<%@ page language="java" contentType="text/html;charset=utf-8" import="java.util.*" import="java.text.SimpleDateFormat" %> <html> <meta http-equiv="refresh" content="1"> <body style=background-color:green > <h1 align="center">歡迎進入聊天室</h1> <hr color="red" /> <form name="form2" method="post" > <%request.setCharacterEncoding("gbk");//獲取用戶名String username =(String) session.getAttribute("username"); //獲取發言內容String message = request.getParameter("message");String show = (String) application.getAttribute("show");//保存歷史記錄SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date = new Date();String time = format.format(date);String Message = username + "在" + time + "說:" + message + "<br>";//application.setAttribute("message", message);if (message!=null) {//message = username + "在" + time + "說:" + message + "<br>";if (application.getAttribute("show") != null){application.setAttribute("show", Message+ "<br>" +application.getAttribute("show").toString());}else{application.setAttribute("show",Message);}} out.println(application.getAttribute("show")); %> </form> </body> </html>


登陸窗口:



聊天窗口截圖:

?梁主任:



海哥:



? 總結:該種功能也可以用在網頁留言上,用session會話保存數據,用戶已登錄就可以查看歷史留言。

總結

以上是生活随笔為你收集整理的Web小应用---网页聊天室的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。