JSP简易聊天室

Posted ITAK

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSP简易聊天室相关的知识,希望对你有一定的参考价值。

这是一个网页版的简易聊天室,做的界面是不是很好 请见谅^_^

<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<form method = "post" action = "chuli.jsp">
用户名:<input type = "text" name = "user"></input><br>
密码:<input type = "password" name = "pass"></input><br>
<input type="submit" value ="登录"></input>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<%
  String us="", ps="";
  us = request.getParameter("user");
  ps = request.getParameter("pass");
  if(ps.equals("123456"))
      session.setAttribute("sess_us", us);
      response.sendRedirect("chat.jsp");
  
  else
      out.print("对不起 您的密码不正确");
  
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
<script type="text/javascript">
  function Judge()
    var s;
    s = chats.say.value;
    if(s=="")
        alert("发言不能为空");
        return false;
    
    return true;
  
 </script>
</head>
<body>
<%
  response.setHeader("refresh","5");
  String sess_us, fy, tmp;
  request.setCharacterEncoding("gbk");
  sess_us = (String)session.getAttribute("sess_us");
  Date now = new Date();
  fy = request.getParameter("say");
  if(fy != "")
    String ans = now.toString()+"   "+sess_us+"说: "+fy+"<br>";
    if(application.getAttribute("app_fy")== "")
        application.setAttribute("app_fy", ans);
    
    else
        tmp = (String)application.getAttribute("app_fy");
        ans = tmp + ans;
        application.setAttribute("app_fy", ans);
    
  
%>
<table border="1" width="800">
<tr><td><%=application.getAttribute("app_fy") %>
</table>

<form action="chat.jsp" method = "post" name = "chats">
  <textarea rows="3" cols="80" name = "say"></textarea><br>
  <input type = "submit" value = "发言" onclick = "return Judge()"></input>

</form>
</body>
</html>

以上是关于JSP简易聊天室的主要内容,如果未能解决你的问题,请参考以下文章

Java实现简易聊天室

[Redis]-Redis简易聊天室

C 基于UDP实现一个简易的聊天室

websocket之简易聊天室

docker搭建swoole简易聊天室

Laravel + Swoole 打造IM简易聊天室