网络聊天室

//chatroom.jsp;

<html style="height: 93px; ">
<head>
<title>网络聊天室</title>
</head>
<frameset rows="*,150">
<frame src="message.jsp">
<frame src="talk.jsp">
</frameset>
</html>

//message.jsp

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="REFRESH" content="1;url=message.jsp">
<script LANGUAGE="JavaScript1.1">
function scrollWindow()
{
this.scroll(0,65000);
setTimeout('scrollWindow()',200);
}
scrollWindow();
</script>
</head>
<body>
<%=application.getAttribute("words") %>
</body>
</html>

//talk.jsp

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%
request.setCharacterEncoding("utf-8"); 
String mywords=request.getParameter("message");
application.log(mywords);
if(mywords!=null)
{
int len_mywords=mywords.length();
int flag=1;
application.log(""+len_mywords);
for(int i=0;i<(len_mywords);i++)
{
if(mywords.charAt(i)=='<')
{
flag=0;
}
}

if(flag==1)
{
mywords=">>:"+mywords;
Object obj=application.getAttribute("words");
if(obj==null)
{
application.setAttribute("words",mywords);
}
else
{
application.setAttribute("words",obj.toString()+mywords+"<br>");
}
}
}%>
<html>
<head> 
<title></title>
</head>

<body>
<form method="post" action="talk.jsp">
<input name="message"type=text size=50>
<input type=submit value=send>
</form>
</body>
</html>

原文地址:https://www.cnblogs.com/liao-pxsoftware15/p/7679381.html