• Struts2 对 cookie的存取


    今天在网上搜索了以下struts2对cookie的操作,结果意外的是,竟然没有可以运行的例子,自己结合多方面资料写了两个函数

        /**
         * 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;
        }
  • 相关阅读:
    nc多校2021-9E.Eyjafjalla
    AcWing第一场周赛题解
    关于Windows和Linux下的对拍
    牛客小白月赛29全题解
    牛客小白月赛32全题解
    牛客小白月赛33全题解
    AC自动机
    Trie树
    KMP
    celery序列化问题
  • 原文地址:https://www.cnblogs.com/Mblog/p/2010740.html
Copyright © 2020-2023  润新知