<!DOCTYPE html>
<html>
<head>
	<title>Login</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<style>
		body {
			background-color: #f1f1f1;
		}
		h1 {
			text-align: center;
		}
		form {
			border: 3px solid #f1f1f1;
			background-color: #fff;
			padding: 20px;
			width: 50%;
			margin: 0 auto;
		}
		input[type=text], input[type=password] {
			width: 100%;
			padding: 12px 20px;
			margin: 8px 0;
			display: inline-block;
			border: 1px solid #ccc;
			box-sizing: border-box;
		}
		button[type=submit] {
			background-color: #4CAF50;
			color: white;
			padding: 14px 20px;
			margin: 8px 0;
			border: none;
			cursor: pointer;
			width: 100%;
		}
		button[type=submit]:hover {
			background-color: #45a049;
		}
		.error {
			color: red;
			text-align: center;
			margin-bottom: 10px;
		}
	</style>
</head>
<body>
	<h1>Login</h1>
	<form action="Check.jsp" method="post">
		<div class="error">
			<% String message = (String)request.getAttribute('message'); if(message != null) { %>
			<%= message %>
			<% } %>
		</div>
		<label for="username"><b>Username</b></label>
		<input type="text" placeholder="Enter Username" name="username" required>
<pre><code>	&lt;label for=&quot;password&quot;&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/label&gt;
	&lt;input type=&quot;password&quot; placeholder=&quot;Enter Password&quot; name=&quot;password&quot; required&gt;

	&lt;button type=&quot;submit&quot;&gt;Login&lt;/button&gt;
&lt;/form&gt;
</code></pre>
</body>
</html>
<p>在 Check.jsp 文件中,使用以下代码进行处理:</p>
<p>&lt;%
String username = request.getParameter('username');
String password = request.getParameter('password');
if(username.equals('admin') &amp;&amp; password.equals('123')) {
response.sendRedirect('Success.jsp');
} else {
response.sendRedirect('Error.jsp');
}
%&gt;</p>
<p>在 Success.jsp 文件中,使用以下代码显示欢迎信息:</p>
<!DOCTYPE html>
<html>
<head>
	<title>Success</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<style>
		body {
			background-color: #f1f1f1;
		}
		h1 {
			text-align: center;
		}
		.success {
			color: green;
			text-align: center;
			font-size: 24px;
			margin-top: 50px;
		}
	</style>
</head>
<body>
	<h1>Success</h1>
	<div class="success">
		Welcome Login
	</div>
</body>
</html>
<p>在 Error.jsp 文件中,使用以下代码显示错误信息并自动回到登录页面:</p>
<!DOCTYPE html>
<html>
<head>
	<title>Error</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<style>
		body {
			background-color: #f1f1f1;
		}
		h1 {
			text-align: center;
		}
		.error {
			color: red;
			text-align: center;
			font-size: 24px;
			margin-top: 50px;
		}
	</style>
	<script>
		setTimeout(function() {
			window.location.href = "Login.html";
		}, 5000);
	</script>
</head>
<body>
	<h1>Error</h1>
	<div class="error">
		Username or Password is incorrect. This page will redirect to Login page in 5 seconds.
	</div>
</body>
</html>
HTML/CSS/JS 登录页面:用户名密码验证并重定向