首页 > 其他 > 详细

Struts2 cookie的存取

时间:2015-05-22 13:08:29      阅读:156      评论:0      收藏:0      [点我收藏+]
/**
     * Cookieの追加
     * @return
     * @throws Exception
     */
    private void addCookie(String name,String value){
        Cookie cookie = new Cookie(name, value);
        cookie.setMaxAge(60*60*24*365);
        ServletActionContext.getResponse().addCookie(cookie);
    }
    /**
     * Cookieの取得
     * @return
     * @throws Exception
     */
    private String getCookie(String name){
        HttpServletRequest request = ServletActionContext.getRequest();
        Cookie[] cookies = request.getCookies();
        for(Cookie cookie : cookies)
        {
            if(cookie.getName().equals(name))
            {
                return cookie.getValue();
            }
        }
        return null;
    }

 

Struts2 cookie的存取

原文:http://www.cnblogs.com/zhujiabin/p/4521828.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!