一个简单的聊天室的登陆,有错误
下面是一个简单的聊天室的登陆,为什么我第一个用户登陆完,第二个用户登陆第一个用户却没有记录进去,后面第三个,第四个.......都是好的,是不是初始化的时候哪里错了
<%@page contentType= "text/html "%>
<%@page pageEncoding= "GB2312 "%>
<%@page import= "java.util.Calendar "%>
<!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=UTF-8 ">
<title> welcome </title>
</head>
<body>
<%! int count=0;
Object talk=null;
int i=1;%>
<%
String iStr=String.valueOf(i);
String countStr=(String)application.getAttribute( "count ");
if (countStr==null)
application.setAttribute( "count ", "1 ");
else {
count+=1;
application.setAttribute( "count ",String.valueOf(count));}
String talkStr=(String)application.getAttribute( "talk ");
if (talkStr==null)
application.setAttribute( "talk ", "talk ");
else {
}
%>
现在聊天室里有 <%= count %> 位访问者
<% i=count;
request.setCharacterEncoding( "UTF-8 ");
String name=(String)request.getParameter( "name ");
String sex=(String)request.getParameter( "sex ");
application.setAttribute( "talk "+i,name);
%>
<%for (int j=1;j <=count;j++)
{%>
现在有访问者分别是: <%= application.getAttribute( "talk "+j) %> ,
<%} %>
<% Calendar cal=Calendar.getInstance();
String yr= String.valueOf(cal.get(Calendar.YEAR));
String mon=String.valueOf(cal.get(Calendar.MONTH)+1);
String dat=String.valueOf(cal.get(Calendar.DATE));
String tim=yr+ "/ "+mon+ "/ "+dat;
%>
<% if ( sex!=null) {
out.println( " <h1> 欢迎 "+name+sex+ "光临 ! "+tim + " </h1> "); %>
<% }else {%>
<h1> 欢迎 <%= name %> 光临 ! <%= tim %> </h1> <%} %>
<%-- application.setAttribute( "talk ",name)--%>
</body>
</html>
[解决办法]
现在聊天室里有3 位访问者 现在有访问者分别是: null, Xu, A,
欢迎 A 光临 !2007/1/19
没什么问题啊