Session

1. SessionID号以Cookie的方式存到客户端,该ID号客户端和服务器端相同。

2.存储在服务器端。

3.不存在子路径、父路径问题。关键是有父子关系的一套窗口:这是同一个session。

4.如果禁用Cookie,则sessionid不能写入到客户端,每次都是新建的session。

 如何解决?

方法:URL重写。

  response.encodeURL(request.getRequestURI().toString());
若Cookie被禁止掉,则获取请求地址后,加上 session id

response:

 StringencodeURL(String url)
          Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.

这就是encodeURL方法的功能。

 

 

request information:

StringBuffergetRequestURL()
          Reconstructs the URL the client used to make the request.

获取客户端此次请求的URL地址。

 StringgetRequestedSessionId()
          Returns the session ID specified by the client.

这个是获取从客户端带来的sessionid。

 booleanisRequestedSessionIdFromCookie()
          Checks whether the requested session ID came in as a cookie.

判断是否从Cookie中获取的sessionid,关键看cookie是否被禁用。

booleanisRequestedSessionIdFromURL()
          Checks whether the requested session ID came in as part of the request URL.

判断是否是通过URL重写得到的sessionid。

 

总结下:

1.session是服务器的一块内存,key-value对;

2.一套客户端窗口对应着一个session;

3.客户端和服务器端有对应的session id;

4.客户端向服务器端发送session id的方式:

   第一:cookie没禁用 cookie中读取;

   第二:cookie被禁用 URL重写。

5.为了安全使用session,应重写URL。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值