Cookie namecookie = new Cookie(cookie_user_name,users.get(0).getLoginName());
namecookie.setMaxAge(60 * 60 * 24 * 365);
namecookie.setPath("/");               //这里设置访问路径
response.addCookie(namecookie);//这里应该是response才对吧,不大确定

解决方案 »

  1.   

    你放错地方了,应该是response才能设置Cookie,request是提取Cookie
      

  2.   

    不好意思,这里我复制之后修改的,原代码是这样的
    this.getActionContext().getResponse().addCookie(namecookie);是放在response里的,还是取不到值
      

  3.   

    this.getActionContext().getResponse().addCookie(namecookie);
    楼主的 this.getActionContext().getResponse() 可以获取到HttpServletResponse对象吗?
    楼主采取哪种方式在struts2中使用servlet呢?是直接让action访问servlet API吗?
      

  4.   

    '${cookie.cookie_user_name.value}'中的cookie.cookie_user_name这个地方没看懂,cookie_user_name不是一个字符串吗,cookie里有cookie_user_name这个东西么
      

  5.   

    js里获取cookie是这样吧document.cookie
      

  6.   

    getActionContext().getResponse()可以取到response对象,因为
    Cookie[] cookies = this.getActionContext().getRequest().getCookies();
                for( Cookie c : cookies ){
                    System.out.println(c.getName()+"--->"+c.getValue());
                }
    这段代码已经取到了
      

  7.   

    楼主是想在jsp页面循环所有的cookie值吗?还是打印某一个特定的cookie值呢?
    ${cookie.jsessionid.value} 获取一个名为jsessionid的cookie值,这个jsessionid 需要提供给el表达式的。
      

  8.   

    EL表达式取COOKIE值我知道是el表达式,cookie对象里有"cookie_user_name"这个属性?