jsp的
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
欢乐聊天室<%--首先取出用户提交的代号名称,保存在变量chatid中--%>
<%
String chatid = new String();
chatid = request.getParameter("inputid");
%>
<%--使用变量flag来标记用户输入是否合法,如果合法,则flag为true --%>
<%
boolean flag;
flag = true;
if(chatid == null){
chatid = "";
}
if(chatid.length() == 0){
flag = false;
}
%>
<%--比较用户所输入的id和目前聊天室中存在的所有id --%>
<%
for(int i=1; i<=6 && flag; i++){
String itemp = new String();
itemp = itemp.valueOf(i);
int num;
String numtemp = new String();
String temp = new String();
temp = "room" + itemp + "usernum";
numtemp = (String)application.getAttribute(temp);
if(numtemp == null){
numtemp = "0";
application.setAttribute(temp ,numtemp);
}
num = Integer.parseInt(numtemp);
for(int j=1; j<=num && flag; j++){
String jtemp = new String();
jtemp = jtemp.valueOf(j);
%>
<%--从application对象中取出第i个聊天室中第j个用户的id,temp变量保存的是application对象用于保存第i个聊天室中第j个用户的id相应的变量名 --%>
<%
temp = "room" + itemp + "user" + jtemp;
String usertemp = new String();
usertemp = (String)application.getAttribute(temp);
if(usertemp.equalsIgnoreCase(chatid)){
flag = false;
}
}
}
int nnn[] = new int[6];
if(flag){
String temproom = new String();
temproom = (String)session.getValue("chatroom");
if(temproom == null){
session.putValue("chatid",chatid);
}
for(int i=1; i<=6; i++) {
String itemp = new String();
itemp = itemp.valueOf(i);
int num;
String numtemp = new String();
String temp = new String();
temp = "room" + itemp + "usernum";
numtemp = (String)application.getAttribute(temp);
if(numtemp == null){
numtemp = "0";
}
num = Integer.parseInt(numtemp);
nnn[i-1] = num;
}
}
%>
欢乐聊天室
<%
if(flag){
%>
<%=chatid %>您好,请选择感兴趣的聊天室!
<%
}else {
%>
id不能为空,或者此id已经被使用,请重新选择!
返回
<%
}
%>