JSP 猜字母游戏

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head>
<body>
    <form action="answer.jsp" method="post">
        <input type="text" name="guess">
        <input type="submit" value="提交">
    </form>
    <%
    String charString=new String("dfngfnkgnfdlkvFGCBVCBCV");
    int charNum=(int)(Math.random()*100+1)%26-1;
    Character tempCharacter=new Character(charString.charAt(charNum));
    session.setAttribute("TempChar", tempCharacter);    
    %>
</body>
</html>

回复

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head>
<body>
    <%
    String tempString=request.getParameter("guess");
    String TempChar=session.getAttribute("TempChar").toString();
    if(tempString !=null){
        //忽略大小写
        if(TempChar.equalsIgnoreCase(tempString)){
            out.println("恭喜你猜对了");
        }else{
            out.println("SB");
        }
    }
    %>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weiyumeizi/article/details/72755650
jsp