还有一个login的jsp页面呢
时间: 2023-11-30 14:40:53 浏览: 84
根据提供的引用内容,我理解您需要一个完整的JSP登录系统,其中包括login.jsp页面。以下是一个简单的JSP登录系统的示例,其中包括login.jsp页面、loginCL.jsp登录验证页面和其他相关页面。
1. login.jsp页面代码:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Page</title>
</head>
<body>
<h1>Login Page</h1>
<form action="loginCL.jsp" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
```
2. loginCL.jsp登录验证页面代码:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Check</title>
</head>
<body>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username.equals("admin") && password.equals("123456")) {
// 登录成功,将用户信息存储到session中
HttpSession session = request.getSession();
session.setAttribute("username", username);
// 跳转到主页
response.sendRedirect("School.jsp");
} else {
// 登录失败,返回登录页面
out.print("<script>alert('Username or password is incorrect!');window.location.href='login.jsp'</script>");
}
%>
</body>
</html>
```
3. School.jsp页面代码:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>School Page</title>
</head>
<body>
<h1>Welcome to School Page</h1>
<%
HttpSession session = request.getSession();
String username = (String) session.getAttribute("username");
if (username == null) {
// 用户未登录,跳转到登录页面
response.sendRedirect("login.jsp");
}
%>
<p>Hello, <%= username %>!</p>
<p>Please select your major:</p>
<ul>
<li><a href="Major.jsp?major=Computer Science">Computer Science</a></li>
<li><a href="Major.jsp?major=Business">Business</a></li>
<li><a href="Major.jsp?major=Engineering">Engineering</a></li>
</ul>
</body>
</html>
```
4. Major.jsp页面代码:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Major Page</title>
</head>
<body>
<h1>Welcome to Major Page</h1>
<%
HttpSession session = request.getSession();
String username = (String) session.getAttribute("username");
String major = request.getParameter("major");
if (username == null) {
// 用户未登录,跳转到登录页面
response.sendRedirect("login.jsp");
}
%>
<p>Hello, <%= username %>!</p>
<p>You have selected <%= major %> as your major.</p>
<p>Please provide your personal information:</p>
<form action="Info.jsp" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
```
5. Info.jsp页面代码:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Info Page</title>
</head>
<body>
<h1>Welcome to Info Page</h1>
<%
HttpSession session = request.getSession();
String username = (String) session.getAttribute("username");
String name = request.getParameter("name");
String email = request.getParameter("email");
if (username == null) {
// 用户未登录,跳转到登录页面
response.sendRedirect("login.jsp");
}
%>
<p>Hello, <%= username %>!</p>
<p>Your name is <%= name %> and your email is <%= email %>.</p>
<p>Thank you for submitting your information.</p>
</body>
</html>
```
阅读全文