Verify the session logon time to verify a listener on the user logon page.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.