1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten<% One A //Check session, get session information -Object obj = Session.getattribute ("username"); - if(obj! =NULL) the { -Out.print ("Welcome login" +obj.tostring ()); - } - Else + { -Out.print ("Session timed out, please log back in to the system"); + //jump to user interface after 3 seconds AResponse.setheader ("Refresh", "3; Url=login.jsp "); at } -%> - Main Page Face -<br> -<a href= "login.jsp" > Sign out </a> -</body> in1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten Login Page One<br> A<% - //Destroy Session - session.invalidate (); the%> - -<form action= "testpw.jsp" method = "POST" > -User name: <input type= "text" name = "username" > +Password: <input type= "password" name = "Password" > -<input type= "Submit" value= "Login" > +</form> A</body> at<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >//Verify that the user logon information is correctString un= Request.getparameter ("username"); String PW= Request.getparameter ("Password");if(UN! =NULL&& PW! =NULL){ //Create session if correct, and jump to main.jsp if(Un.equals ("ASD") && pw.equals ("123")) { //Log User InformationSession.setattribute ("username", un); //jump to System main PageResponse.sendredirect ("main.jsp"); } Else { //Otherwise, prompt for login errorOut.print ("User name or password error"); }}Else{out.print ("Please access the system in a normal way"); }%></body>Learn to record Java session save user Login