getAttribute("LOGINED_USER");
for(StringloginedUser:
loginedUsers)//存在过,
{
if(username.equals(loginedUser))
{
flag=1;
out.print("〈script>alert(’此昵称已有人使用过!
请重新输入');location。
href='login.jsp’;”);
// response。
sendRedirect("login.jsp");
}
}
if(flag==0){
ListnewUser=new ArrayList〈String〉();
loginedUsers。
add(username);
newUser.add(username);
session.setAttribute(”LOGINED_USER",newUser);
session。
setAttribute("username”, username);//存储用户名,方便检测
application.setAttribute("LOGINED_USER",loginedUsers);
response.sendRedirect(”game.jsp”);
}
}
if(application。
getAttribute(”LOGINED_USER")==null){
ListnewUser=newArrayList<String〉();
loginedUsers.add(username);
newUser。
add(username);
session.setAttribute(”LOGINED_USER”,newUser);
session.setAttribute("username",username);//存储用户名,方便检测
application。
setAttribute(”LOGINED_USER”,loginedUsers);
response。
sendRedirect("game.jsp”);
}
%>
游戏jsp中game。
jsp
〈%@page language="java"import=”java.util.*"pageEncoding=”UTF-8"%〉
〈%
Stringpath=request.getContextPath();
String basePath= request。
getScheme()+":
//"+request。
getServerName()+”:
”+request.getServerPort()+path+"/”;
StringnickName=(String)session。
getAttribute("username");
if(session。
getAttribute("username")==null){
ﻩresponse.sendRedirect("login。
jsp");
}
Objectgtime=application。
getAttribute(nickName+"gtime”);
if(gtime==null){//第一次
application。
setAttribute(nickName+”gtime",1+"");
}else{
ﻩint gt=Integer。
parseInt((String)gtime);
ﻩgt=gt+1;
ﻩapplication.setAttribute(nickName+"gtime”,gt+””);//增加次数
}
int number=(int)(Math.random()*10);
session.setAttribute("save”,number);
%〉
〈!
DOCTYPEHTMLPUBLIC”-//W3C//DTDHTML4。
01Transitional//EN”>
〈head〉
〈base href=”〈%=basePath%〉">
ﻩ〈metahttp—equiv="cache—control”content="no-cache”〉
<metahttp—equiv="expires”content=”0">
ﻩ〈metahttp—equiv=”keywords”content="keyword1,keyword2,keyword3”>
〈metahttp-equiv="description”content=”Thisismypage”〉
〈!
—-
〈link rel=”stylesheet"type=”text/css”href=”styles。
css"〉
-—>
〈/head>
<script〉
//varrandom=Math.floor(Math。
random()*10);
//Integer integer=(Integer)session.getAttribute(”save");
varrandom=〈%=session。
getAttribute("save”)%〉;
document.write(random);
vartime=0;
functioncheck(){
ﻩvar answers=document。
getElementById(”answer").value;
if(random!
=answers){
if(random〉answers){
alert("Sorry!
你所猜的数比实际的数小");time=time+1;
}else{alert("Sorry!
你所猜的数比实际的数大”);time=time+1; }
}else{
alert("恭喜你!
猜对了”);location.href='request。
jsp?
success=true';
}
if(time==3){
alert("Sorry!
游戏失败”);location。
href='request。
jsp';
}
}
script>
<body>
〈center>
请输入你所猜的数字:
〈FORMname=form >
〈inputtype="text”id=”answer”/〉
〈inputtype="button"value="送出"onclick=”check()"/〉
</FORM〉
</center〉
〈/body>
〈/html>
排行榜jsp中rank。
jsp
<%@pagelanguage=”java"import="java。
util。
*”pageEncoding=”UTF-8"%>
<%
Stringpath=request。
getContextPath();
String basePath= request.getScheme()+":
//”+request.getServerName()+”:
”+request.getServerPort()+path+"/”;
StringnickName=(String)session。
getAttribute(”user");
if(request。
getParameter("success”)!
=null){
ﻩObjectstime=application。
getAttribute(nickName+"stime”);
if(stime==null){//第一次
ﻩﻩapplication.setAttribute(nickName+"stime”,1+"");
ﻩ}else{
intst=Integer.parseInt((String)stime);
ﻩst=st+1;
ﻩﻩapplication.setAttribute(nickName+"stime”,st+””);//增加次数
}
}
%〉
<!
DOCTYPEHTML PUBLIC ”-//W3C//DTDHTML4.01Transitional//EN”〉
<html>
〈head〉
〈basehref="〈%=basePath%>"〉
〈title〉My JSP ’request.jsp’startingpage
ﻩ〈metahttp—equiv="pragma” content="no-cache"〉
ﻩ〈metahttp—equiv=”expires”content=”0"〉
〈metahttp—equiv=”keywords” content=”keyword1,keyword2,keyword3”〉
ﻩ〈metahttp-equiv="description"content=”Thisismypage”>
ﻩ
——
ﻩ〈linkrel="stylesheet” type="text/css”href="styles。
css">
-->
〈/head>
<body〉
〈center〉
是否继续游戏?
〈br>
jsp”>是</a〉 ;&nbsp;&nbsp;
<ahref="login。
jsp?
exit=true”〉退出