• jsp第四周作业


    1、登录(login.jsp)

     
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>登录页面</title>
        <style type="text/css">
            body{margin: 0;}
            #login_div{height: 720px;background-color: darkslategray;padding-top: 30px;}
            form{text-align: center;float: right;margin-right: 30px;}
            input{ 280px;height: 30px;margin-top: 10px;}
            img{ 280px;height: 30px;margin-top: 10px;}
            .btn{background-color: #009F95;opacity: 0.7; 280px;}
        </style>
    </head>
    <body>
    <div id="login_div">
    
        <form action="Verification.jsp" method="post" >
            <div style="font-size: 25px;color: #01AAED;">欢迎登录</div>
            <input type="text" name="username" placeholder="请输入账户"/><br>
            <input type="password" name="password" placeholder="请输入密码"><br>
            <img id="captcha" src="${pageContext.request.contextPath}/captcha" onclick="refresh()"/><br>
            <input type="text" name="captcha" placeholder="请输入4位验证码"/><br>
            <input id="login" type="submit" value="登录" class="btn"/><br>
            <input id="autoLogin" type="submit" value="已登录" class="btn"/><br>
        </form>
    
    </div>
    <script>
        function refresh() {
            document.getElementById("captcha").src="${pageContext.request.contextPath}/captcha?"+new Date().getTime();
        }
    </script>
    </body>
    </html>

    2、验证(Verication.jsp)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <%
        String captcha = request.getParameter("captcha");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String realCap = (String) session.getAttribute("captcha");
    
        if(session.getAttribute("username")!=null&&session.getAttribute("password")!=null){
            request.getRequestDispatcher("success.jsp").forward(request,response);
        }
    
    //    判断是否为空
        if(username!=null&&password!=null&&captcha!=null){
            //判断账户、密码、验证码是否正确
            if(captcha.equalsIgnoreCase(realCap)&&username.equals("zs")&&password.equals("123")){
                session.setAttribute("username",username);
                session.setAttribute("password",password);
                request.getRequestDispatcher("success.jsp").forward(request,response);
            }else {
                response.sendRedirect("login.jsp");
            }
    
        }
    
    %>
    </body>
    </html>


    3、首页(success.jsp)
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <h1 style="text-align: center">
        WELCOME:<%=session.getAttribute("username")%>Mr XXX
    </h1>
    </body>
    </html>
  • 相关阅读:
    java中获取服务器的IP和端口
    springboot项目 配置https
    vue+element+upload实现头像上传
    js指定日期时间加一天 ,判断指定时间是否为周末
    在内网中 vue项目添加ECharts图表插件
    vue+element树组件 实现树懒加载
    iview 表格随着更改刷新
    vue设置input不可编辑切换
    .Net程序员学用Oracle系列(3):数据库编程规范
    .Net程序员学用Oracle系列(2):准备测试环境
  • 原文地址:https://www.cnblogs.com/Hackman/p/14590094.html
Copyright © 2020-2023  润新知