One: JSP landing page login.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8" />
<title>登录页 - Java教程:http://www.javaweb.cc</title>
</head>
<body>
<form action="login.jsp" method="post">
用户名:<input type="text" name="uname" /><br />
密 码:<input type="password" name="upass" /></br />
<input type="submit" value=" 登 录 " />
<input type="reset" value=" 重 置 " />
</form> String password = request.getParameter("upass"); // Get password information String name = request.getParameter("uname"); // Get name information // Username: admin Password: 123
<%
if(!(name == null || "".equals(name) || password == null || "".equals(password))) // Verify username and password
{
response.setHeader("refresh" , "2; URL = welcome.jsp"); // Timely jump
session.setAttribute("userid", name); // The user name of the successful login is saved in the session
%>
<h3> The user is successfully logged in, two seconds Jump to the welcome page after the bell! </h3>
<h3>If there is no automatic jump, please press <a href="welcome.jsp">here</a></h3>
<%
}
else
{
%>
<h3>Wrong username or password ! </h3>
<%
}
%>
</body>
</html>
2. JSP login success page (welcome page) welcome.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login Welcome Page - Java Chinese Website: http://www.javaweb.cc</title>
</head>
<body>
<%
if(session.getAttribute("userid") != null) / / The attributes that have been set, all are not empty
{
%>
<h3>Welcome<%= session.getAttribute("userid") %> Visit this site, your SessionID is: <%= session.getId() %> <a href="logout.jsp">Logout</a>! </h3>
<%
}
else // Illegal user, if the login is not passed, there is no attribute in the session scope
{
%>
3. JSP logout page logout.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Logout Page - JAVAWEB.CC</title>
</head>
<body>
The SessionID before logout is: <%= session.getId() %> <br /> The attribute is: <%= session.getAttribute ("userid") %> <br />
<%
response.setHeader("refresh", "2; URL = login.jsp"); // regular jump
session.invalidate(); // logout session
%>
logout The later SessionID is: <%= session.getId() %> The attribute is: <br />
<h3>You have successfully launched the system, jump to the login page in two seconds</h3>
<h3>If there is no automatic jump, please click <a href="login.jsp">here</a></h3>
</body>
</html>