SpringMVC框架的登陆与注册功能

1.创建一个新的项目

2.编写后端程序代码

1.User类

public class User {
    private String username;
    private String password;
    private String sex;
    private String birthday;

    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;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String Sex) {
        this.sex = sex;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
}

2.controller层

@Controller
public class a {
   List<User> list = new ArrayList<>();
    @RequestMapping("q")
    public String q(){
        return "zhuce";
    }

    @RequestMapping("w")
    public String s(User a){
        list.add(a);
        return "denglu";
    }

    @RequestMapping("e")
    public String s(String username, String password){
        for (User a: list ){
            if (a.getUsername().equals(username)&&a.getPassword().equals(password)){
                return "success";
            }
        }
        return "denglu";
    }

3.编写前端页面代码

zhuce.jsp

<html>
<head>
    <title>Title</title>
</head>
<body>

<form action="w" method="post">
    姓名: <input type="username" name="username"><br>
    密码: <input type="password" name="password"><br>
    性别: <input type="xingbie" name="xingbie"><br>
    生日: <input type="生日" name="shengri"><br>
    <input type="submit" name="shengri">

</form>
</body>
</html>

denglu.jsp

<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="e" method="post">
    姓名: <input type="username" name="username"><br>
    密码: <input type="password" name="password"><br>

    <input type="submit" name="shengri">
</form>
</body>
</html>

success.jsp

<html>
<head>
    <title>Title</title>
</head>
<body>
<h1>登陆成功</h1>
</body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值