technological learning session:
Question:
- A user's data sharing deal with different requests of how to do?
Solution:
Use technology session
* Principle:
-
The first time a user accesses the server, the server will create a session object to the user, and the session object
-
JSESSIONID other requests to use the Cookie stored in the browser technology, to ensure that the user can obtain the same
-
session object, but also to ensure the different requests to the shared data can be acquired
-
Features:
-
存储在服务器端
-
服务器进行创建
-
依赖Cookie技术
-
一次会话
-
默认存储时间是30分钟
effect:
-
Use:解决了一个用户不同请求处理的数据共享问题
Create a session object / Get session object
HttpSession hs = req.getSession();
If the request has a session identifier is JSESSIONID, it returns the corresponding formation session
if the request is not in session identifier is JSESSIONID, then create a new session object and data storage JSESSIONID as a cookie to the browser in
if the session object is invalid, and will re-create a session object and JSESSIONID stored in the browser memory
setting session storage time
hs.setMaxInactiveInterval(int seconds);
Note:
the session object is not being used and destroyed within a specified period of time, if a re-timing
Set session forced failure
hs.invalidate ();
Store and retrieve data
storage: hs.setAttribute (String name, Object value );
Get: hs.getAttribute (String name) Object to return data type
Note:
storage operation and the extraction operation occur in different request, the memory to performed prior to removing
使用时机:
一般用户在登录web项目时会将用户的个人信息存储到Sesion中,供该用户的其他请求使用
总结:
session解决了一个用户的不同请求的数据共享问题,只要在JSESSIONID不失效和session对象不失效的情况下
用户的任意请求在处理时都能获取到同一个sessioon对象
Scope:
a session
for the entire project within JSESSIONID and in the case of failure of the object is not SESSION
session失效处理:
将用户请求中的JSESSIONID和后台获取到的SESSION对象的JSESSIONID,进行比对,如果一致
则session没有失效,如果不一致则证明session失效了.重定向到登录页面,让用户重新登录
- note:
- JSESSIONID Cookie is stored in the temporary storage space, the browser is closed shall lapse