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>