JSP实现简单聊天室的问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 04:47:09
下面是这个聊天室的全部代码:
<%@ page language="java" pageEncoding="GBK"%>
<html>
<head>
<title>My JSP 'lab.jsp' starting page</title>
</head>

<body>
<%
if(application.getAttribute("chat")!=null)
{ if(request.getParameter("mywords")!=null)
{ String mywords=request.getParameter("mywords");
mywords=(String)application.getAttribute("chat")+"<br>"+mywords;
application.setAttribute("chat",mywords);
out.print((String)application.getAttribute("char"));
}
}
%>
<form action="lab.jsp" method="get">
<input type="text" size="30" name="mywords" value="我喜欢聊天">
<input type="sumbit" na

改成下面的样子:
<%@ page language="java" pageEncoding="GBK"%>
<html>
<head>
<title>My JSP 'lab.jsp' starting page</title>
</head>

<body>
<%
if(application.getAttribute("chat")!=null)
{ if(request.getParameter("mywords")!=null)
{ String mywords=request.getParameter("mywords");
mywords=(String)application.getAttribute("chat")+"<br>"+mywords;
application.setAttribute("chat",mywords);
out.print((String)application.getAttribute("chat"));
}
}else{
application.setAttribute("chat","");
}
%>
<form action="a1.jsf" method="post">
<input type="text" size="30" name="mywords" value="我喜欢聊天">
<input type="submit" name="sumbit" val