首页 > 其他分享 >新写一个jsp项目之一:登录模块

新写一个jsp项目之一:登录模块

时间:2024-03-28 22:22:22浏览次数:19  
标签:Code 模块 登录 新写 jsp background 页面 View

参考:https://blog.csdn.net/qq_41301333/article/details/131202057

一、纯JSP方式实现用户登录功能
(一)实现思路
登录页面login.jsp,输入用户名和密码后,跳转到登录处理页面doLogin.jsp进行业务逻辑处理,登录成功,跳转到登录成功页面success.jsp,否则跳转到登录失败页面failure.jsp。
(二)实现步骤

 

<%--
  Created by IntelliJ IDEA.
  User: liu
  Date: 2024/3/28
  Time: 20:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .a{
            border-style: solid ;
            border-color: purple;
            width: 30%;
            height: 40%;
            margin: auto;
            /*position: absolute;*/
            /*left: 0;*/
            /*top: 0;*/
            /*bottom: 0;*/
            /*right: 0;*/
            background-color: lightgrey;
        }
        .b{
            text-align: center ;
            background-repeat: no-repeat ;
            background-position:center center;
            background-size:cover;
            background-attachment: fixed;
        }
    </style>
</head>
<body background="./image/beijing.jpg" class='b'>
<form action="doLogin.jsp" method="post">
    <table border="1" cellpadding="10" style="margin: 0px auto">
        <tr>
            <td align="center">账号</td>
            <td><input type="text" name="username"/></td>
        </tr>
        <tr>
            <td align="center">密码</td>
            <td><input type="password" name="password"/></td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <input type="submit" value="登录"/>
                <input type="reset" value="重置"/>
            </td>
        </tr>
    </table>
</form>

</body>
</html>
View Code
<%--
  Created by IntelliJ IDEA.
  User: liu
  Date: 2024/3/28
  Time: 20:07
  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("903213")) {
        // 跳转到登录成功页面,传递用户名
        response.sendRedirect("success.jsp?username=" + username);
    } else {
        // 跳转到登录失败页面,传递用户名
        response.sendRedirect("failure.jsp?username=" + username);
    }
%>
</body>
</html>
View Code
<%--
  Created by IntelliJ IDEA.
  User: liu
  Date: 2024/3/28
  Time: 20:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录</title>
</head>
<body>
<h3 style="text-align: center">用户登录</h3>
<form action="doLogin.jsp" method="post">
    <table border="1" cellpadding="10" style="margin: 0px auto">
        <tr>
            <td align="center">账号</td>
            <td><input type="text" name="username"/></td>
        </tr>
        <tr>
            <td align="center">密码</td>
            <td><input type="password" name="password"/></td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <input type="submit" value="登录"/>
                <input type="reset" value="重置"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
login.jsp
<%--
  Created by IntelliJ IDEA.
  User: liu
  Date: 2024/3/28
  Time: 20:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录成功</title>
</head>
<body>
<h3 style="text-align: center">恭喜,<%=request.getParameter("username")%>,登录成功!</h3>
</body>
</html>
View Code
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: liu
  Date: 2024/3/28
  Time: 20:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录失败</title>
</head>
<body>
<h3 style="text-align: center">抱歉,<%=request.getParameter("username")%>,登录失败!</h3>
<%
    // 打印当前日期和时间
    System.out.println(request.getParameter("username"));
%>
</body>
</html>
View Code

 

标签:Code,模块,登录,新写,jsp,background,页面,View
From: https://www.cnblogs.com/vactor/p/18102765

相关文章

  • 【selinux】linux的信息安全模块 - selinux
    1.Selinux简介selinux全称(Security-EnhancedLinux)安全增强型Linux,它是一个Linux内核模块,也是Linux的一个安全子系统。2.Selinux的作用及权限管理机制2.1Selinux的作用SELinux主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。2.2DAC在没有使用SE......
  • Python中模块
    基本概念**模块module:**一般情况下,是一个以.py为后缀的文件①Python内置的模块(标准库);②第三方模块;③自定义模块。包package:当一个文件夹下有   init   .py时,意为该文件夹是一个包(package),其下的多个模块(module)构成一个整体,而这些模块(module)都可通过同一个包(packa......
  • Python math 模块
    Pythonmath模块Python math 模块提供了许多对浮点数的数学运算函数。math 模块下的函数,返回值均为浮点数,除非另有明确说明。如果你需要计算复数,请使用 cmath 模块中的同名函数。要使用math函数必须先导入:importmath查看math模块中的内容:importmathprint......
  • [附源码]计算机毕业设计保险客户管理系统(JSP+java+springmvc+mysql+MyBatis)
    本项目包含程序+源码+数据库+LW+调试部署环境,文末可获取一份本项目的java源码和数据库参考。项目文件图项目介绍在现代保险行业中,客户管理系统对于提升客户服务水平、增强客户满意度和构建长期客户关系至关重要。随着大数据和人工智能技术的发展,保险公司迫切需要一个先进的......
  • [附源码]计算机毕业设计技术文档管理系统(JSP+java+springmvc+mysql+MyBatis)
    本项目包含程序+源码+数据库+LW+调试部署环境,文末可获取一份本项目的java源码和数据库参考。项目文件图项目介绍技术文档管理系统是企业信息化建设的重要组成部分,它关系到知识的积累、共享和管理效率。随着企业规模的扩大和业务的多样化,传统的文件管理方式已无法满足快速检......
  • 中间件和Auth模块
    中间件1.Django中间件介绍【1】什么是Django中间件Django中间件是一个轻量级、可重用的组件,用于处理Django请求和响应的过程。它提供了对请求和响应进行全局处理的机制,可以在请求达到视图之前进行预处理或在响应返回给客户端之前进行后处理。中间件是按照顺序依次执行的,每......
  • 【异常】IDEA运行单元测试覆盖率统计时,出现运行 整个项目(4)时出错,配置按模块工作目录
    一、报错内容运行整个项目(4)时出错:配置按模块工作目录时将禁用‘覆盖’。只指定一个工作目录,或将测试范围更改为一个模块。二、报错说明这段文字描述了一个在运行整个项目时遇到的错误。错误信息提示说,在配置按模块工作目录时,将禁用’覆盖’。为了解决这个问题,建议......
  • FLASK学习记录-Jinja2模块引擎
    Flask中引入了jinja2模板引擎,可以显示动态数据、数据过滤、语句控制、模板继承和引用等。实战实例app.pyfromflaskimportFlask,render_templateapp=Flask(__name__)@app.route('/')defindex():LibraryName="NationalLibrary"visitor={"name":"J......
  • importlib模块
    importimportlibres='myfile.b'ret=importlib.import_module(res)#frommyfileimportb#该方法最小只能到py文件名print(ret)  defsend_all(content):forpath_strinsettings.NOTIFY_LIST:#'notify.email.Email'module_path,cl......
  • FPGA入门笔记010——UART串口接收模块设计
    1、串口接收模块原理​当对于数据线Rs232_Rx上的每一位进行采样时,一般情况下认为每一位数据的中间点是最稳定的。因此一般应用中,采集中间时刻时的电平即认为是此位数据的电平,如图1所示。图1——串口接收时序图(图中BPS_CLK为采样时钟)​但是在实际工业应......