The session is automatically cleared when the page is closed.

Source: Internet
Author: User

By default, the session object is not destroyed immediately after the browser is closed. Therefore, to consider the security of the system, the session object needs to be cleared immediately when the user exits, prevent others from stealing information from session objects.

The main method to clear the content of a session object is as follows:

(1) removeattribute () method. This method is used to delete the specified property information stored in the session object.

Example: Session. setattribute ("name", "Iverson"); Session. removeattribute ("name ");

(2), invalidate () method. This method can clear all information in the session object.

Example: Session. invalidate ().

Generally, after the browser is closed, the session information can be cleared only after the session object expires. If you need to disable the browser to clear the session information, try the following methods.

<Body onbeforeunload = "window. Location = 'logout. jsp '">

You can do this on the logout. jsp page: <% httpsession session = request. getsession (); Session. invalidate (); %>

Today, there are many frameworks based on the MVC Architecture Model. ThereforeCode, Directly separated from the JSP page according to the selected MVC framework.

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.