【简单的前端静态登陆界面】

代码如下:可根据需求自行修改

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <style>
        body {
            background-color: #f5f5f5;
            font-family: Arial, sans-serif;
            font-size: 16px;
            color: #333;
            margin: 0;
            padding: 0;
        }
        form {
            width: 400px;
            margin: 100px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
        }
        h1 {
            text-align: center;
            margin: 0 0 20px;
        }
        label {
            display: block;
            margin-bottom: 10px;
        }
        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 16px;
            margin-bottom: 20px;
            box-sizing: border-box;
        }
        input[type="submit"] {
            background-color: #333;
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #555;
        }
    </style>
</head>
<body>
    <form>
        <h1>登录</h1>
        <label for="username">用户名:</label>
        <input type="text" id="username" name="username">
        <label for="password">密码:</label>
        <input type="password" id="password" name="password">
        <input type="submit" value="登录">
    </form>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
首先,在Spring Boot中,静态页面应该放在`src/main/resources/static`目录下。 其次,为了实现登录功能,您需要使用一个表单来收集用户的用户名和密码,并将这些信息提交到后端。以下是一个简单的示例: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Login</title> </head> <body> <h2>Login</h2> <form method="post" action="/login"> <label for="username">Username:</label> <input type="text" id="username" name="username"><br><br> <label for="password">Password:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Submit"> </form> </body> </html> ``` 在这个表单中,我们定义了两个输入框,一个用于输入用户名,一个用于输入密码。当用户点击“提交”按钮时,表单将会被提交到`/login`地址。 接下来,您需要在后端实现`/login`地址的处理逻辑,以验证用户的身份。以下是一个简单的示例: ```java @Controller public class LoginController { @PostMapping("/login") public String login(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session) { if ("admin".equals(username) && "123456".equals(password)) { session.setAttribute("username", username); return "redirect:/home"; } else { return "redirect:/login?error"; } } @GetMapping("/login") public String login() { return "login"; } @GetMapping("/home") public String home(HttpSession session) { String username = (String) session.getAttribute("username"); if (username != null) { return "home"; } else { return "redirect:/login"; } } } ``` 在这个控制器中,我们定义了三个请求处理方法: - `login()`方法用于返回登录页面的视图。 - `login()`方法用于处理用户提交的表单数据,并验证用户名和密码是否正确。如果验证通过,我们将`username`存储到`HttpSession`中,并重定向到`/home`地址。否则,我们将用户重定向回`/login`地址,并在URL中添加一个`error`参数,以提示用户登录失败。 - `home()`方法用于返回主页面的视图。如果用户已经登录(即`username`存在于`HttpSession`中),我们将返回主页面的视图。否则,我们将用户重定向回`/login`地址。 最后,您可以在`src/main/resources/templates`目录下创建`login.html`和`home.html`两个视图文件,分别用于显示登录页面和主页面的内容。以下是这两个文件的示例代码: ```html <!-- login.html --> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Login</title> </head> <body> <h2>Login</h2> <form method="post" action="/login"> <label for="username">Username:</label> <input type="text" id="username" name="username"><br><br> <label for="password">Password:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Submit"> </form> <p th:if="${param.error}">Invalid username or password.</p> </body> </html> ``` ```html <!-- home.html --> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Home</title> </head> <body> <h2>Welcome, <span th:text="${session.username}"></span>!</h2> <a href="/logout">Logout</a> </body> </html> ``` 在这些HTML文件中,我们使用了`thymeleaf`模板引擎来渲染动态内容。在`login.html`中,我们使用了`${param.error}`来检查是否有`error`参数被添加到URL中,并在页面上显示相应的错误消息。在`home.html`中,我们使用了`${session.username}`来获取`HttpSession`中存储的用户名,并欢迎用户到达主页面。 希望这可以帮助您实现登录静态页面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

武帝为此

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值