zoukankan      html  css  js  c++  java
  • JSP第四次(2.0)

    index.jsp

    复制代码
    <%@ page import="java.util.Random" %>
    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <!DOCTYPE html>
    <html>
    <head>
        <title>登录</title>
    </head>
    <body>
    <form action="login.jsp" method="post">
        <p>账号:<label>
            <input type="text" name="username">
        </label></p>
        <p>密码:<label>
            <input type="password" name="password">
        </label></p>
        <p>验证码:<label>
            <input type="number" name="verify">
        </label>
        <label>
            <%
                Random rdm = new Random();
                int code1 = rdm.nextInt(100);
                int code2 = rdm.nextInt(100);
            %>
            <input type="number" name="code1" value="<%=code1%>" hidden>
            <input type="number" name="code2" value="<%=code2%>" hidden>
            <%=code1%>+<%=code2%>(输入该算式的值)
        </label></p>
        <input type="submit" value="登录">
    </form>
    </body>
    </html>
    复制代码

    login.jsp

    复制代码
    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <html>
    <head>
        <title>登录结果</title>
    </head>
    
    <body>
    <%
        String loginInfo = "";
        String sign = "";
        try
        {
            String code1 = request.getParameter("code1");
            String code2 = request.getParameter("code2");
            String verify = request.getParameter("verify");
            int code1Int = Integer.parseInt(code1);
            int code2Int = Integer.parseInt(code2);
            int verifyInt = Integer.parseInt(verify);
            if (code1Int + code2Int != verifyInt)
                loginInfo = "登录失败,验证码不正确";
            else
            {
                String username = request.getParameter("username");
                String password = request.getParameter("password");
                if (username.equals("zs") && password.equals("123"))
                {
                    loginInfo = "登录成功";
                    sign = "hidden";
                }
                else
                    loginInfo = "登录失败,账号密码错误";
            }
        }
        catch (Exception e)
        {
            loginInfo = "登录失败,参数错误";
        }
    %>
    <p><%=loginInfo%></p>
    <form action="index.jsp" method="get">
        <input type="submit" value="返回登录" <%=sign%>>
    </form>
    </body>
    </html>
    复制代码

     

     

    密码错误时:

     验证码不正确时:

     

  • 相关阅读:
    寫程序方法
    phpDesigner注冊碼
    如何获取SQL Server数据库元数据(转)
    WPF中的事件(Event)
    访问数据源的架构信息(系统表、信息结构图、GetSchema)
    MSbuild生成WPF程序
    数据契约
    window动态调整大小后无法关闭
    sql server 2000 系统表详细介绍(转,收藏一下)
    Linq2Sql:使用Sqlmetal.exe
  • 原文地址:https://www.cnblogs.com/Study-xia678/p/14622671.html
Copyright © 2011-2022 走看看