HttpSession explanation,

Source: Internet
Author: User

HttpSession explanation,
1: session authentication principle:

When the client accesses the server for the first time, the client request does not carry any identifier to the server, so the server cannot find the corresponding

Session, so the session object will be created. When the server responds, the server will put the session identifier in the Set-Cookie of the Response Header

Return key-value to the client, for example, JSESSIONID = 7F149950097E7B5B41B390436497CD21; where JSESSIONID is fixed,

The value next corresponds to the ID of the newly created session for the client. When the browser accesses the server again, the client will

Put it in the cookie and request the server, the server will find the corresponding session object based on this ID; (when the browser is closed, the session ends, because the cookie is cleared

The corresponding session Object Identifier disappears, and the corresponding session still exists, but it has become decommissioned data waiting for GC to be recycled)

You can use this method to obtain the corresponding session ID: session. getId ();

 

2: session lifecycle:

For example, you can use the following method:

 

3. Examples of common methods:

Logon interface:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 

Display interface:

1 <% @ page language = "java" contentType = "text/html; charset = UTF-8" 2 pageEncoding = "UTF-8" %> 3 <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" http://www.w3.org/TR/html4/loose.dtd "> 4 

Logout interface:

1 <% @ page language = "java" contentType = "text/html; charset = UTF-8" 2 pageEncoding = "UTF-8" %> 3 <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" http://www.w3.org/TR/html4/loose.dtd "> 4 

When you log on to the console for the first time:

Enter the name Lily in userName and click "Log on:

When you click "re-login" again, the session is used for data echo. The session is not canceled, so the session remains unchanged:

When the Logout button is clicked, the logon session becomes invalid and the original session object is destroyed:

After you click "Log on again" or refresh the page, a new session will be created:

 

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.