求用Java编写的聊天室界面
发布网友
发布时间:2022-04-24 01:46
我来回答
共4个回答
热心网友
时间:2023-10-19 17:20
jsp的
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>欢乐聊天室</title>
</head>
<body>
<%--首先取出用户提交的代号名称,保存在变量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;
}
}
%>
<p align="center"><b><font face="隶书" size="6" color="#FF00FF">欢乐聊天室</font></b></p>
<%
if(flag){
%>
<p align="center"><font color="red"><%=chatid %></font>您好,请选择感兴趣的聊天室!</p>
<center><table border="1" width="370">
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=1">今天我们相识(<%=nnn[0]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=2">校园的那条小路(<%=nnn[1]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=3">职场淘金(<%=nnn[2]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=4">网络技术交流(<%=nnn[3]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=5">世界体育大看台(<%=nnn[4]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=6">新闻背后的故事(<%=nnn[5]%>)</a></td>
</tr>
</table><center>
<%
}else {
%>
<center><p>id不能为空,或者此id已经被使用,请重新选择!</p><center>
<p><center><a href="login.html">返回</a><center></p>
<%
}
%>
</body>
</html>
热心网友
时间:2023-10-19 17:20
swing学了没什么用,企业不招
热心网友
时间:2023-10-19 17:21
很奇怪,为什么老师让你写这么没用的东西呢?貌似很少用java写界面的
热心网友
时间:2023-10-19 17:21
不会写代码的话,用netbeans吧,一拖一拉5分钟搞定。
热心网友
时间:2023-10-19 17:20
jsp的
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>欢乐聊天室</title>
</head>
<body>
<%--首先取出用户提交的代号名称,保存在变量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;
}
}
%>
<p align="center"><b><font face="隶书" size="6" color="#FF00FF">欢乐聊天室</font></b></p>
<%
if(flag){
%>
<p align="center"><font color="red"><%=chatid %></font>您好,请选择感兴趣的聊天室!</p>
<center><table border="1" width="370">
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=1">今天我们相识(<%=nnn[0]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=2">校园的那条小路(<%=nnn[1]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=3">职场淘金(<%=nnn[2]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=4">网络技术交流(<%=nnn[3]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=5">世界体育大看台(<%=nnn[4]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=6">新闻背后的故事(<%=nnn[5]%>)</a></td>
</tr>
</table><center>
<%
}else {
%>
<center><p>id不能为空,或者此id已经被使用,请重新选择!</p><center>
<p><center><a href="login.html">返回</a><center></p>
<%
}
%>
</body>
</html>
热心网友
时间:2023-10-19 17:20
swing学了没什么用,企业不招
热心网友
时间:2023-10-19 17:21
很奇怪,为什么老师让你写这么没用的东西呢?貌似很少用java写界面的
热心网友
时间:2023-10-19 17:21
不会写代码的话,用netbeans吧,一拖一拉5分钟搞定。