javaee好看登录页面的代码
时间: 2023-09-01 15:10:30 浏览: 38
以下是一个简单的JavaEE登录页面的代码示例,包括HTML,CSS和Java代码:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="login.css">
</head>
<body>
<div class="login-box">
<h2>Login Here</h2>
<form action="login" method="post">
<p>Username</p>
<input type="text" name="username" placeholder="Enter Username">
<p>Password</p>
<input type="password" name="password" placeholder="Enter Password">
<input type="submit" name="login" value="Login">
</form>
</div>
</body>
</html>
```
CSS代码:
```css
body {
background: #333;
font-family: sans-serif;
}
.login-box {
width: 400px;
height: 400px;
background: #fff;
color: #333;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%,-50%);
box-sizing: border-box;
padding: 70px 30px;
}
h2 {
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
.login-box p {
margin: 0;
padding: 0;
font-weight: bold;
}
.login-box input {
width: 100%;
margin-bottom: 20px;
}
.login-box input[type="text"], input[type="password"] {
border: none;
border-bottom: 1px solid #333;
background: transparent;
outline: none;
height: 40px;
color: #333;
font-size: 16px;
}
.login-box input[type="submit"] {
border: none;
outline: none;
height: 40px;
background: #333;
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.login-box input[type="submit"]:hover {
cursor: pointer;
background: #ffc107;
color: #000;
}
```
Java代码:
```java
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
// Check if username and password are valid
if(username.equals("admin") && password.equals("admin123")) {
response.sendRedirect("home.jsp");
} else {
response.sendRedirect("login.jsp");
}
}
}
```
在这个例子中,我们使用了Servlet来处理登录请求。当用户提交表单时,Servlet将检查用户名和密码是否正确。如果它们是正确的,用户将被重定向到主页(home.jsp),否则用户将被重定向回登录页面(login.jsp)。
通过HTML和CSS,我们创建了一个简洁而漂亮的登录界面。登录框位于屏幕的中央,并使用黄色按钮来吸引用户的注意力。