下面是一个简单的聊天室的登陆,为什么我第一个用户登陆完,第二个用户登陆第一个用户却没有记录进去,后面第三个,第四个.......都是好的,是不是初始化的时候哪里错了<%@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>

解决方案 »

  1.   

    现在聊天室里有3 位访问者 现在有访问者分别是: null, Xu, A, 
    欢迎 A 光临 !2007/1/19没什么问题啊
      

  2.   

    你做一个登陆界面就行了  这样直接运行 
    第一个人就是null 如果不在url后面加上?name=...的话
      

  3.   

    可是第一个a,显示没问题,现在聊天室里有1 位访问者 现在有访问者分别是: a,
        第二个b,就会显示     现在聊天室里有1 位访问者 现在有访问者分别是: b,
    第三个c,就会显示     现在聊天室里有2 位访问者 现在有访问者分别是: b,c后面都没问题,就是第一个显示的a没了
      

  4.   

    sorry啊。登陆界面忘了发了 
    第一贴发的chatroom.jsp下面这个发的是login.jsp<%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
    --%><!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>JSP Page</title>
        </head>
        <body>    <h1>欢迎进入任你聊聊天室</h1>
        
     <form name="login" method="post" action="chatroom.jsp" accept-charset="GB2312">
         <input type="txt" name=name value="">
         <input type="radio" name=sex value="先生"> 男
          <input type="radio" name=sex value="女士"> 女
          <input type="submit" name=submit value="登陆">
           <input type="reset" name=reset value="取消">
     </form>
        
        </body>
    </html>