下面是一个简单的聊天室的登陆,为什么我第一个用户登陆完,第二个用户登陆第一个用户却没有记录进去,后面第三个,第四个.......都是好的,是不是初始化的时候哪里错了<%@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>
<%@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>
解决方案 »
- 我配置了opensessioninview 都生效了但是获取set的时候报错了
- 在myeclipse中开发struts需要引入的jar包是什么????
- JSP有没有像PHP那样的模板技术,分离HTML代码和程序代码
- 求助,jsp,大家帮帮忙
- 利用Ant(Hibernate *.hbm.xml)建数据库时出错(SchemaExport)在线等……
- 数据库访问问题
- dwr中的java.sql.Date类型需要提供转换器么,出现了如下错误
- 用session机制保存用户登录信息,用户正常登录后却获得了别的用户的信息,大虾帮帮忙!
- 一道SQL面试题,看能难倒了多少人?
- 江湖救急:在jsp下怎么实现把查询出来的数据导入Excel表格中?解决了送100分,谢谢
- jsp里提示对话框的问题
- 输出的时间格式要修改一下,请问如下变动?
欢迎 A 光临 !2007/1/19没什么问题啊
第一个人就是null 如果不在url后面加上?name=...的话
第二个b,就会显示 现在聊天室里有1 位访问者 现在有访问者分别是: b,
第三个c,就会显示 现在聊天室里有2 位访问者 现在有访问者分别是: b,c后面都没问题,就是第一个显示的a没了
第一贴发的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>