2021-05-26

本文档描述了一个基于Java的Web登录系统实现过程。包括创建登录页、使用session存储用户信息、Servlet验证登录、错误页面及注销功能。系统检查cookie中的用户名和密码,正确则登录成功,否则重定向至错误页面。用户可通过注销链接清理session数据并返回登录页。
摘要由CSDN通过智能技术生成

首先创建一个登录页

创建一个current_user值 使用session方法储存

创建一个判断如果不为空这转到index.jsp(登录成功)页面

<%--
  Created by IntelliJ IDEA.
  User: wyl
  Date: 2021/5/25
  Time: 9:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登陆页面</title>
</head>
<body>
<%
    String current_user = (String)session.getAttribute("current_user");
    if (current_user!=null){
        response.sendRedirect("index.jsp");
    }
    //获取所有cookie数字
    String username = "";
    String password = "";
    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies){
        out.print(cookie.getName()+"-----"+cookie.getValue());
        //cookie通过键值对的形式来储存数据
        if (cookie.getName().equals("username")){
            //获取到值
            username = cookie.getValue();
            continue;
        }
        if (cookie.getName().equals("password")){
            password = cookie.getValue();
            continue;
        }
    }
%>
<form action="servlet.jsp" method="get">
    <table>
        <tr>
            <td>用户名</td>
            <td><input type="text"name="username" placeholder="请输入用户名"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" name="password" placeholder="请输入密码"></td>
        </tr>
        <tr>
            <td><input type="submit" value="提交"></td>
            <td><input type="reset" value="重置"></td>
        </tr>
    </table>
</form>
</body>
</html>

创建一个servlet.jsp()页面

创建一个username 和 password把login的用户名和密码转过来判断

如果正确就保存进current_user 然后进入index.jsp(登录成功)页面

如果不正确则进入error.jsp(登陆失败页面)

<%--
  Created by IntelliJ IDEA.
  User: wyl
  Date: 2021/5/25
  Time: 9:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<%
    //判断用户信息
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if (username.equals("王雨亮")&&password.equals("123")){
        session.setAttribute("current_user",username);
        Cookie usernamecookie = new Cookie("username",username);
        Cookie userpasswordcookie = new Cookie("password",password);
        //设置Cookie存活事件
        usernamecookie.setMaxAge(18000);
        userpasswordcookie.setMaxAge(18000);
        response.addCookie(usernamecookie);
        response.addCookie(userpasswordcookie);
        response.sendRedirect("index.jsp");
    }else {
        response.sendRedirect("error.jsp");
    }
%>
</body>
</html>

创建一个index.jsp

使用session方法获取其中的信息,判断如果为空的话就是其中没有保存用户名和信息则转到login.jsp

(登陆页)页面

最后超链接是链接clean_session.jsp点击之后用来删除session中储存的数据然后转到login.jsp

<%--
  Created by IntelliJ IDEA.
  User: wyl
  Date: 2021/5/25
  Time: 9:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>首页</title>
</head>
<body>
<%
    /*获取session中的信息*/
    String current_user = (String) session.getAttribute("current_user");
    if (current_user == null){
        //如果session中没有当前的用户信息,表示用户还没有登陆
        response.sendRedirect("login.jsp");
    }
%>
<h1>
    早上好啊!<%=current_user%> , 今天好高兴美好的一天!!!!!!!!!!!!!!!!!!!!!!
</h1>
<a href="clean_session.jsp">logout</a>
</body>
</html>

创建一个clean_session.jsp页面

用于删除session中的数据,然后挑战到login.jsp(登录页)

<%--
  Created by IntelliJ IDEA.
  User: wyl
  Date: 2021/5/25
  Time: 11:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>当前页面主要作用是清空用户登录信息</title>
</head>
<body>
<%
    //删除session中的数据
    session.removeAttribute("current_user");
    //删除后再次跳入首页,判断是否清除成功
    response.sendRedirect("index.jsp");
%>
</body>
</html>

最后创建一个error.jsp页面

主要显示失败之后的页面

<%--
  Created by IntelliJ IDEA.
  User: wyl
  Date: 2021/5/25
  Time: 9:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h1 style="color: red;text-align: center">用户名或密码错误</h1>
</body>
</html>

 

2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值