HttpSession源码翻译

package javax.servlet.http;

import java.util.Enumeration;
import javax.servlet.ServletContext;

/**
 * 目的:识别用户并存储用户信息
 * 
 * <p>识别用户访问多个网页或一个网址,并存储用户信息。
 * 
 * <p>servlet容器使用该接口创建一个session。在session的保留时间内,用户
 * 可以跨越多个连接或页面请求。一个session对应一个用户。服务端能以多种方式来
 * 维护session,如:Cookie或重写URL。
 * 
 * <p>该接口允许servlet有以下操作:
 *    a. 查看和操作session信息,如:sessionID、创建时间、最后访问时间;
 *    b. 绑定对象,允许用户信息跨越多请求连接。
 * 
 * <p>当应用程序从session中存储或删除对象时,session会检查该对象是否实现
 * {@link HttpSessionBindingListener}。若实现,servlet将通知
 * 对象,session是否绑定了。绑定方法完成之后进行通知。对于session的无效或
 * 过期,session无效或过期之后进行通知。
 * 
 * <p>分布式容器设置中,当容器在VM之间迁移session时,所有的session将实现
 * {@link HttpSessionActivationListener}接口。
 * 
 * <p>servlet能够处理用户没有参加session的情况,比如:客户端Cookie关闭。
 * 客户端没有参加session时,isNew返回为true。对于客户端的每一个请求,
 * getSession将返回不同的session,并且isNew总是为true。
 * 
 * <p>Session范围仅是当前web应用程序(ServletContext),信息都存在
 * ServletContext中,其他应用程序不会看到。
 * @author TCM
 * @create 2017年10月26日上午10:00:00
 * @see    HttpSessionBindingListener
 * @see    HttpSessionContext
 */
public interface HttpSession {

    //session的创建时间
    public long getCreationTime();
    //获取sessionID
    public String getId();
    //客户端最后访问时间
    public long getLastAccessedTime();
    //返回该session所属的ServletContext对象
    public ServletContext getServletContext();
    //设置session无效的间隔时间,单位:秒
    public void setMaxInactiveInterval(int interval);
    public int getMaxInactiveInterval();

    /**
     * 返回该session绑定的对象,若没有返回null
     * @exception IllegalStateException
     */
    public Object getAttribute(String name);
    public Enumeration<String> getAttributeNames();
    public void setAttribute(String name, Object value);
    public void removeAttribute(String name);

    /**
     * 将session无效,然后解除该session绑定的任何对象
     * @exception IllegalStateException	
     */
    public void invalidate();
    
    /**
     * 若果客户端没有session或没有参加session,将返回true。
     * 例如:客户端禁用Cookie,那么对于每一个请求都创建一个新的session。
     * @return 	返回true,创建一个session
     * @exception IllegalStateException
     */
    public boolean isNew();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下展示部分源码,需要完整版的请下载文件 <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> <style> *{margin:0;padding:0;list-style:none} body{background:#ccc;} .wrap{margin:100px auto;width:900px;height:300px;box-shadow:0 0 4px #434343;background:#fff;padding:20px;border-radius:10px;} .wrap .language{position:relative;width:100px;height:30px;padding:0 30px;margin:20px;text-align:center;line-height:30px;border:1px solid #434343;cursor:pointer;} .wrap .language .languages{position:absolute;top:30px;left:-1px;width:354px;height:auto;border:1px solid #434343;display:none;background:#fff;color:#fff;line-height:40px} .wrap .language .languages ul li{float:left;width:78px;height:40px;margin:4px; border:1px dashed #ccc;background:#368;} .wrap .input, .wrap .show{width:430px;height:150px;float:left;background:#fff; color:#000;margin:10px;box-shadow:0 0 4px #222;line-height:40px;font-size:20px;text-indent:10px;color:#333;font-family:'微软雅黑';} .wrap .input textarea{z-index:3;height:100%;width:400px;border:0;resize:none;outline:0;color:#333;font-family:'微软雅黑';margin:0;padding:0;line-height:40px;font-size:20px;text-indent:10px;} .wrap span.btn{width:140px;height:30px;float:right;margin:10px;line-height:30px;text-align:center;background:#368;box-shadow:0 0 4px #ccc;border-radius:5px;color:#fff;cursor:pointer;} </style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值