JSF Cookie kullanımı

JSF te cookie kullanıcı için aşağıdaki utility class ını inceleyebilirsiniz.

    package com.bookinturkey.session.util;
     
    import javax.faces.context.FacesContext;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    public class CookieUtil {
     
     public void setCookie(String name, String value, int exp){
      FacesContext facesContext = FacesContext.getCurrentInstance();
      Cookie cookie = new Cookie(name, value);
      cookie.setMaxAge(exp);
      ((HttpServletResponse)facesContext.getExternalContext().getResponse()).addCookie(cookie);
     }
     public String getCookie(String name){
      String value=null;
      FacesContext facesContext = FacesContext.getCurrentInstance();
      Cookie cookie[] = ((HttpServletRequest)facesContext.getExternalContext().getRequest()).getCookies();
      if (cookie != null && cookie.length > 0) {
       for (int i = 0; i < cookie.length; i++) {
        if(cookie[i].getName().equals("name")){
         value = cookie[i].getValue();
        }
       }
      }
     
     
      return value;
     }
    }
Apr 10th, 2009
Tags: ,
  1. balamir
    Apr 3rd, 2011 at 20:50 | #1

    if(cookie[i].getName().equals(“name”)){

    satiri sanirim

    if(cookie[i].getName().equals(name)){

    şeklinde olacakti

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>