Home > Java > javaTutorial > body text

How to generate jsessionid

(*-*)浩
Release: 2020-09-19 14:02:14
Original
9155 people have browsed it

Jsessionid is just Tomcat’s name for sessionid, which is actually sessionid; it may not be called jsessionid in other containers.

First of all, let’s talk about the creation of session objects in web development and the operating mechanism of generating and returning sessionId to the client.

How to generate jsessionid

The session object is accessed for the first time by the client. At the same time, create a new session object. At the same time, a sessionId is generated, and in this response, the sessionId is returned to the client browser memory in the form of a response message or sent back to the client in the form of rewriting the URL to maintain the entire Session, as long as the session object on the server side is not destroyed, when request.getSession() is called in the future, the session object generated by the server side will be directly retrieved based on the client's sessionId and returned. It will not be created again unless the sessionId is not retrieved. session object.

The following is tested under IE, because a BUG of IE6.0 is that even when all cookies are blocked, IE's privacy settings will still use session cookies to save the sessionId. Therefore, the following are all based on session cookies. discussed.

(1) When the server is not closed and within the session object destruction time, when the client requests the server-side servlet or jsp again, the sessionId generated in the first request will be appended. In the request header and sent to the server, after receiving the sessionId, the server will search for the session object corresponding to the server based on this sessionId (this process is transparent) and directly return the session object. At this time, it will not re-create a session object. New session object.

(2) When the server is closed (the previously generated session object will also die), or after the session object has passed its destruction time, the browser window will not close and will be browsed in this session. When the server window requests the servlet and jsp on the server side again, the sessionId (sessionId generated when the server is closed or the session is destroyed) will also be sent to the server side. The server will find its corresponding session object based on the sessionId, but at this time the session object No longer exists. At this time, a new session object will be regenerated, a new sessionId will be generated, and the newly generated sessionId will also be sent to the browser memory in the form of a response message.

(3) . When the server is not closed and the session object is within its destruction time, when a jsp page is requested back to the client, the browser window is closed. At this time, the sessionId in its memory is also destroyed, and the server is requested again. When using servlet or jsp, a sessionId will be regenerated to the client browser and stored in the browsing memory.

To summarize, the workflow of jsessionid can be simply represented by the following figure:

How to generate jsessionid

Related learning recommendations: java basics

The above is the detailed content of How to generate jsessionid. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template