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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JSP网络聊天室

發布時間:2023/12/18 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JSP网络聊天室 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 實現思路

1.???? 登錄頁面

在頁面輸入用戶名密碼,提交到登錄邏輯頁面

2.???? 登錄邏輯頁面

調數據庫判斷用戶名密碼的正確性

正確:跳到聊天室界面并且存儲用戶名

錯誤:返回登錄界面

3.聊天室界面

?? 1.拿到存儲的用戶名

2.將發送的消息傳到聊天室邏輯頁面

3.拿到application中的值將application中的值展示到聊天記錄文本域中

?

4.聊天室邏輯頁面

將傳過來的消息用application域對象存儲起來

獲取之前application中的值

2、邏輯思路圖

?

3、實例代碼:

Login.jsp? 登錄頁面

<form action="loginOpreation.jsp" method="post"> 用戶名:<input type="text" name="uname" ><br/> 密碼:<input type="password" name="upass" ><br/> <input type="submit" value="登錄" > </form>

LoginOperation.jsp?登錄邏輯頁面

<!-- 登錄邏輯頁面 --><%String uname=request.getParameter("uname");String upass=request.getParameter("upass");BuserDao bd=new BuserDao();Buser b=new Buser(uname,upass);if(bd.Login(b)){session.setAttribute("uname", uname);session.setAttribute("upass", upass);request.getRequestDispatcher("chatRoom.jsp").forward(request, response); }else{response.sendRedirect("login.jsp");}

chatRoom?? 聊天室

<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <!-- <meta http-equiv="refresh" content="5;url=chatRoom.jsp"> --><title>Insert title here</title><script type="text/javascript"> function $(o){return document.getElementById(o); } function s(){var str=$("input").value;if(str==""){alert("輸入框不能為空,請輸入!");}else{document.location="chatRoomOpreation.jsp?sendInfo="+str;;} } </script> </head> <body> <% request.setCharacterEncoding("UTF-8"); //獲取application中的值 String all=""; Object o=application.getAttribute("all"); if(o!=null){all=o.toString();} %><h1>多人聊天室</h1> 你好:<%=session.getAttribute("uname") %> <form method="post"> <div style="width:1000px; height:350px; overflow:auto; border:1px solid #000000;"> <%=all %> </div> <br/> <!-- 第二種,輸入框 --><input type="text" name="sendInfo" id="input"/> <!-- 第二種,富文本編輯器 --> <!-- <textarea rows="10" cols="10" name="sendInfo" id="1"></textarea> <script type="text/javascript">CKEDITOR.replace("sendInfo"); </script> --><input type="button" value="發送" οnclick="s()"> </form></body>


chatRoomOpreation.jsp 聊天室邏輯頁面

<!-- 聊天業務邏輯頁面 --> <% request.setCharacterEncoding("UTF-8"); //獲取用戶名,用戶名要拼接在發送的消息的前面 String uname=session.getAttribute("uname").toString(); //獲取application中記錄 String all=""; Object o=application.getAttribute("all"); if(o!=null){all=o.toString(); } //1.獲取要發送的內容 String sendInfo=request.getParameter("sendInfo").toString(); if(sendInfo==null){request.setAttribute("flage","YES");request.getRequestDispatcher("chatRoom.jsp").forward(request, response);//response.sendRedirect("chatRoom.jsp"); } //將內容拼接 if("admin".equals(uname)){all=all+"<br/>"+uname+":<span style='color:red'>"+sendInfo+"</span>"; } else if("sa".equals(uname)){all=all+"<br/>"+uname+":<span style='color:green'>"+sendInfo+"</span>"; } //富文本編輯器內容拼接// all=all+"\r\n"+uname+":"+sendInfo; //2.將獲取的內容存到application中 application.setAttribute("all",all); //3.跳轉到chatRoom.jsp頁面(重定向) response.sendRedirect("chatRoom.jsp");%>



總結

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

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