This repository has been archived on 2025-01-14. You can view files and clone it, but cannot push or open issues/pull-requests.
computer-web/src/main/webapp/login.jsp

62 lines
2.2 KiB
Plaintext

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
// 绑定表单提交事件
$('#loginForm').submit(function (event) {
event.preventDefault(); // 阻止表单默认提交行为
// 获取表单数据
const formData = $(this).serialize();
// 异步请求
$.ajax({
url: '/login',
type: 'POST',
data: formData,
dataType: 'json',
success: function (response) {
if (response.status === 'success') {
alert(response.message);
window.location.href = '/computer?action=list'; // 跳转至主页
} else {
$('#message').text(response.message).css('color', 'red');
}
},
error: function () {
$('#message').text('请求失败,请稍后重试').css('color', 'red');
}
});
});
// 刷新验证码
$('#captchaImage').click(function () {
$(this).attr('src', '/captcha?timestamp=' + new Date().getTime());
});
});
</script>
</head>
<body>
<h2>-电脑商城-用户登录</h2>
<form id="loginForm">
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required><br><br>
<label for="captcha">验证码</label>
<input type="text" id="captcha" name="captcha" required>
<img id="captchaImage" src="/captcha" alt="验证码" style="cursor: pointer;" title="点击刷新验证码"><br><br>
<button type="submit">登录</button>
<a href="/register">没有账号?去注册</a>
</form>
<br>
<p id="message"></p>
</body>
</html>