Chklogin.jsp:
<% @ page language = "java" pageEncoding = "GBK" import = "news.admin. *"%> < Head>
// Query the database, verify the username and password if (! Checkmanagers.checklogin (!, Password)) {%> username or password may be incorrect. Please go back.
Return TO Admin Entrance <%} else {
// indicate the session with the login name. Session.setttribute ("Unique_Check_String", UserName); Response.sendRedirect ("main.jsp");}%> body> html>
Session-Guard.jsp:
<% @ page language = "java" pageEncoding = "GBK"%> <% string uniqueCheckstring = (string) session.getattribute ("unique_check_string"); if (uniqueCheckstring == null) {
// Destroy the current session session.invalidate ();
/ / Redirect the homepage to the web application. After transferring to the home page, the server will automatically create a new session. This new session does not contain the login name, and cannot access the restricted page. Response.sendRedirect (Request.GetContextPath () "/index.jsp"); // To prevent the response.sendredirect () statement from conflicting with the protected page itself, RETURN statement should be protected using Return statement The statement in the page. Return;}%>
Main.jsp:
/ / Add this in any JSP page that needs to be protected:
<% @ include file = "/ admin / session-guard.jsp"%>