1. Before successful login_do.jsp login (preferred for SUN Enterprise applications)
Add
Session. setAttribute ("user", admin );
I added the following in my Verification Action:
Admin admin = dbu. selectAdmin (login. getAdmin_user ());
HttpSession session = request. getSession ();
Admin is your administrator POJO;
The user name and password are stored in the admin.
User is for later use, can be said to be a pointer, or a key, admin is a value
2. Write a sessionCheck. jsp file (preferred for SUN Enterprise applications) to verify the session
<% @ Page pageEncoding = "UTF-8" contentType = "text/html; charset = UTF-8" %>
<% @ Include file = "/admin/sessionCheck. jsp (preferred for SUN Enterprise Applications)" %>
<% @ Page import = "com. fypl. Admin" %>
<%
Object obj = session. getAttribute ("user ");
If (obj = null ){
Out. print ("You have not logged on ");
Response. sendRedirect ("admin_login.jsp (preferred for SUN Enterprise Applications )");
} Else {
Admin admin = (Admin) obj;
}
%>
The first line is to set a key, which is paired with its value.
In fact, this key is used to operate on its value.
If the key is null, the value is null.
So you are not logged on, because after login, there must be an account and password
Otherwise .... Please leave
If it is not empty, forcibly convert the key to a value.
3. The above two parts have been completed. The most important step is below.
The following statements are contained in the header of each jsp (preferred for SUN Enterprise Applications) file:
<% @ Include file = "/admin/sessionCheck. jsp (preferred for SUN Enterprise Applications)" %>
In this way, if you do not log on, you will want to access this page. It will first execute sessionCheck. jsp (preferred for SUN Enterprise applications)
Check whether the account password is empty.
Of course, it will be blank if you do not log on.