jsp唯美登录注册界面代码
时间: 2023-09-24 12:09:52 浏览: 34
以下是一个简单的 JSP 登录注册界面代码示例,包含了基本的样式和表单验证:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Login & Register</title>
<style type="text/css">
body {
background-color: #f8f8f8;
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 1.5;
color: #333;
}
h1, h2 {
margin-top: 0;
font-weight: normal;
}
.container {
margin: 50px auto;
padding: 20px;
max-width: 500px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
border-radius: 5px;
}
form {
margin-top: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"], input[type="password"] {
display: block;
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
background-color: #fff;
box-sizing: border-box;
margin-bottom: 15px;
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 1.5;
color: #333;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 14px;
font-weight: bold;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
.error {
color: red;
font-size: 12px;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Login & Register</h1>
<ul>
<li><a href="#login-form">Login</a></li>
<li><a href="#register-form">Register</a></li>
</ul>
<form id="login-form" action="login.jsp" method="post">
<h2>Login</h2>
<label>Username:</label>
<input type="text" name="username" required>
<label>Password:</label>
<input type="password" name="password" required>
<input type="submit" value="Login">
<c:if test="${not empty error}">
<div class="error">${error}</div>
</c:if>
</form>
<form id="register-form" action="register.jsp" method="post">
<h2>Register</h2>
<label>Username:</label>
<input type="text" name="username" required>
<label>Password:</label>
<input type="password" name="password" required>
<label>Confirm Password:</label>
<input type="password" name="confirm_password" required>
<input type="submit" value="Register">
<c:if test="${not empty error}">
<div class="error">${error}</div>
</c:if>
</form>
</div>
</body>
</html>
```
该代码使用了 JSP 和基本的 HTML/CSS,包含了两个表单和一些基本的样式。需要注意的是,该代码中的表单验证仅做了简单的必填项验证,实际应用中需要根据具体情况进行更严格的验证。