<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>登录</title>
	<style>
		body {
			background-color: #f7f7f7;
		}
		form {
			margin: 100px auto;
			width: 300px;
			padding: 20px;
			background-color: #fff;
			box-shadow: 0 0 10px #ccc;
		}
		input {
			display: block;
			margin: 10px auto;
			padding: 5px;
			width: 100%;
			font-size: 16px;
			border: 1px solid #ccc;
			border-radius: 5px;
			box-sizing: border-box;
		}
		input[type="submit"] {
			background-color: #007fff;
			color: #fff;
			cursor: pointer;
			transition: background-color 0.3s ease;
		}
		input[type="submit"]:hover {
			background-color: #0066cc;
		}
		.error {
			color: red;
			font-size: 14px;
			margin-top: 10px;
			text-align: center;
		}
	</style>
</head>
<body>
	<form action="Check.jsp" method="post" onsubmit="return checkForm()">
		<label for="username">用户名:</label>
		<input type="text" id="username" name="username" placeholder="请输入用户名">
		<label for="password">密码:</label>
		<input type="password" id="password" name="password" placeholder="请输入密码">
		<input type="submit" value="登录">
	</form>
	<script>
		function checkForm() {
			var username = document.getElementById("username").value.trim();
			var password = document.getElementById("password").value.trim();
			if (username === '' || password === '') {
				alert('用户名和密码不能为空!');
				return false;
			}
			return true;
		}
	</script>
</body>
</html>
<p>/* 无需添加CSS代码 */</p>
<p>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;
pageEncoding=&quot;UTF-8&quot;%&gt;
&lt;%
String username = request.getParameter(&quot;username&quot;);
String password = request.getParameter(&quot;password&quot;);
if (&quot;admin&quot;.equals(username) &amp;&amp; &quot;123&quot;.equals(password)) {
response.sendRedirect(&quot;Success.jsp&quot;);
} else {
response.sendRedirect(&quot;Error.jsp&quot;);
}
%&gt;</p>
<p>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;
pageEncoding=&quot;UTF-8&quot;%&gt;</p>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>成功</title>
	<style>
		body {
			background-color: #f7f7f7;
		}
		.container {
			margin: 100px auto;
			width: 300px;
			padding: 20px;
			background-color: #fff;
			box-shadow: 0 0 10px #ccc;
			text-align: center;
		}
		h1 {
			font-size: 24px;
			margin-bottom: 20px;
			color: #007fff;
		}
	</style>
</head>
<body>
	<div class="container">
		<h1>欢迎登录</h1>
	</div>
</body>
</html>
<p>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;
pageEncoding=&quot;UTF-8&quot;%&gt;</p>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>错误</title>
	<style>
		body {
			background-color: #f7f7f7;
		}
		.container {
			margin: 100px auto;
			width: 300px;
			padding: 20px;
			background-color: #fff;
			box-shadow: 0 0 10px #ccc;
			text-align: center;
		}
		h1 {
			font-size: 24px;
			margin-bottom: 20px;
			color: red;
		}
		p {
			font-size: 16px;
			margin-bottom: 20px;
		}
		.countdown {
			font-size: 16px;
			color: #007fff;
		}
		.redirect {
			font-size: 16px;
			margin-top: 20px;
		}
	</style>
	<script>
		var countdown = 5;
		window.setInterval(function() {
			countdown--;
			if (countdown === 0) {
				window.location.href = "Login.html";
			} else {
				document.getElementById("countdown").innerHTML = countdown;
			}
		}, 1000);
	</script>
</head>
<body>
	<div class="container">
		<h1>用户名或密码错误</h1>
		<p>该页面显示<span id="countdown" class="countdown">5</span>秒后自动回到用户登录页面。</p>
		<p class="redirect">如果没有自动跳转,请点击<a href="Login.html">这里</a>.</p>
	</div>
</body>
</html>
HTML/CSS/JS 实现简单登录页面并重定向 - 用户名密码验证