主题:聊天室的页面如何刷新?
如题,这样显然是不行的,每2秒刷新一次,那么request.getParameter()就会得到相应的参数,并重复存到application中,其实这些话日用户以前说过的/就是这个问题。即使你只说一句,过会IE就会都成刚才说不得话了/
<%@page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>聊天室</title>
<meta CONTENT=“text/html";charset="GBK2312">
<%
if(request.getProtocol().compareTo("HTTP/1.0")==0)
response.setHeader("pragma","no-cache");
else if(request.getProtocol().compareTo("HTTP/1.1")==0)
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",-1);
response.setHeader("Refresh","2");
%>
</head>
<body bgcolor="#ffffff">
<%
String user = (String) session.getAttribute("user");
String chat, chats;
chat = request.getParameter("mychat");
chats = (String) application.getAttribute("chats");
if (user != null) {
if (chat != null) {
chat = user+":" + chat;
if (chats != null)
chats = chats + "<br>"+chat;
else
chats = chat;
}
else {
if (chats == null)
chats = "";
}
application.setAttribute("chats", chats);
%>
<%=application.getAttribute("chats") %>
<center>
<form action="jsp3.jsp">
<input type="text" name="mychat"/>
<input type="submit" value="发送"/>
</form>
</center>
<%
} else {
out.println("<a href='jsp1.jsp'>请先登陆</a>");
}
%>
</body>
</html>
<%@page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>聊天室</title>
<meta CONTENT=“text/html";charset="GBK2312">
<%
if(request.getProtocol().compareTo("HTTP/1.0")==0)
response.setHeader("pragma","no-cache");
else if(request.getProtocol().compareTo("HTTP/1.1")==0)
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",-1);
response.setHeader("Refresh","2");
%>
</head>
<body bgcolor="#ffffff">
<%
String user = (String) session.getAttribute("user");
String chat, chats;
chat = request.getParameter("mychat");
chats = (String) application.getAttribute("chats");
if (user != null) {
if (chat != null) {
chat = user+":" + chat;
if (chats != null)
chats = chats + "<br>"+chat;
else
chats = chat;
}
else {
if (chats == null)
chats = "";
}
application.setAttribute("chats", chats);
%>
<%=application.getAttribute("chats") %>
<center>
<form action="jsp3.jsp">
<input type="text" name="mychat"/>
<input type="submit" value="发送"/>
</form>
</center>
<%
} else {
out.println("<a href='jsp1.jsp'>请先登陆</a>");
}
%>
</body>
</html>