Servlet的登录验证

 

index.jsp:

复制代码
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2019/10/15
  Time: 11:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Servlet登录界面</title>
</head>
<body>
<form action="<%=request.getContextPath()%>/demo"method="post">

    <table align="center">
        <tr><td>
            账号姓名: <input type="text"name="userName"placeholder="请输入账号姓名"><br><br>
            密码: &nbsp;&nbsp;&nbsp; <input type="password"name="password"placeholder="请输入密码"><br><br>
            <input type="submit"value="登录">

        </td></tr>
    </table>
</form>


</body>
</html>
复制代码

shibai.jsp:

复制代码
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2019/10/15
  Time: 11:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Servlet登录失败页面</title>
    <style>
        h1{
            color: red;
        }
    </style>
</head>
<body>

<h1>登录失败</h1>

</body>
</html>
复制代码

 

success.jsp:

 

复制代码
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2019/10/15
  Time: 11:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Servlet登录成功页面</title>
    <style>
        h1{
            color: green;
        }
    </style>
</head>
<body>

<h1>登录成功</h1>
</body>
</html>
复制代码

 

表单验证:

MyServlet:

复制代码
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2019/10/15
  Time: 11:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Servlet登录成功页面</title>
    <style>
        h1{
            color: green;
        }
    </style>
</head>
<body>

<h1>登录成功</h1>
</body>
</html>
复制代码

pojo中User类:

复制代码
package pojo;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

public class User{
    private String userName;
    private String password;


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
复制代码

 

本文作者:AxeBurner

本文链接:https://www.cnblogs.com/bichen-01/p/11676619.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   AxeBurner  阅读(622)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.