Package javax.servlet.http

Examples of javax.servlet.http.Cookie


        }
        return headerName;
    }

    private Cookie getCookie(String cookieName, InjectionPoint ip) {
        Cookie cookie = null;
        for (Cookie c : request.getCookies()) {
            if (c.getName().equals(cookieName)) {
                cookie = c;
                break;
            }
        }

        if (cookie == null) {
            String defaultValue = getDefaultValue(ip);
            if (defaultValue != null) {
                cookie = new Cookie(cookieName, defaultValue);
            }
        }

        return cookie;
    }
View Full Code Here


  public Cookie[] getCookies() {
    List<Cookie> cookies = new ArrayList<Cookie>();
    if ( ! fCookies.isEmpty() ) {
      for(String name: fCookies.keySet()){
        String value = fCookies.get(name);
        Cookie cookie = new Cookie(name, value);
        cookies.add(cookie);
      }
    }
    return cookies.isEmpty() ? null : cookies.toArray(new Cookie[0]);
  }
View Full Code Here

    Cookie[] cookies = aRequest.getCookies();
    if ( cookies != null ){
      List cookieList = Arrays.asList(cookies);
      Iterator iter = cookieList.iterator();
      while ( iter.hasNext() ) {
        Cookie cookie = (Cookie)iter.next();
        result.put(cookie.getName(), "Value:" + cookie.getValue() + ", Comment:" + cookie.getComment() + ", Domain:" + cookie.getDomain() + ", Max-Age:" + cookie.getMaxAge() + ", Path:" + cookie.getPath() + ", Spec- Version:" + cookie.getVersion());
      }
      result = sortMap(result);
    }
    return result;
  }
View Full Code Here

  public void index(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

    String cookieName = request.getParameter("cookiename");
    String cookieValue = request.getParameter("cookievalue");
    Cookie aCookie = null;
    if (cookieName != null && cookieName.length() > 0 && cookieValue != null) {
      aCookie = new Cookie(cookieName, cookieValue);
      response.addCookie(aCookie);
    }

    response.setContentType("text/html");
    out.println("<html>");
    out.println("<body bgcolor=\"white\">");
    out.println("<head>");

    String title = RB.getString("cookies.title");
    out.println("<title>" + title + "</title>");
    out.println("</head>");
    out.println("<body>");

    // relative links

    // XXX
    // making these absolute till we work out the
    // addition of a PathInfo issue

    out.println("<a href=\"../cookies.html\">");
    out.println("<img src=\"../images/code.gif\" height=24 " + "width=24 align=right border=0 alt=\"view code\"></a>");
    out.println("<a href=\"../index.html\">");
    out.println("<img src=\"../images/return.gif\" height=24 " + "width=24 align=right border=0 alt=\"return\"></a>");

    out.println("<h3>" + title + "</h3>");

    Cookie[] cookies = request.getCookies();
    if ((cookies != null) && (cookies.length > 0)) {
      out.println(RB.getString("cookies.cookies") + "<br>");
      for (int i = 0; i < cookies.length; i++) {
        Cookie cookie = cookies[i];
        out.print("Cookie Name: " + HTMLFilter.filter(cookie.getName()) + "<br>");
        out.println("  Cookie Value: " + HTMLFilter.filter(cookie.getValue()) + "<br><br>");
      }
    } else {
      out.println(RB.getString("cookies.no-cookies"));
    }
View Full Code Here

import javax.servlet.http.HttpServletRequest;

public class Cookies {

  public static String getCookie (HttpServletRequest req, String sName, String sDefault) {
    Cookie aCookies[] = req.getCookies();
    String sValue = null;

    for (int c=0; c<aCookies.length; c++) {
      if (aCookies[c].getName().equals(sName)) {
        sValue = URLDecoder.decode(aCookies[c].getValue());
View Full Code Here

    return sValue!=null ? sValue : sDefault;
  } // getCookie()

  public static String getCookie (HttpServletRequest req, String sName, String sDefault, String sEncoding)
    throws java.io.UnsupportedEncodingException {
    Cookie aCookies[] = req.getCookies();
    String sValue = null;

    if (null != aCookies) {
      for (int c=0; c<aCookies.length; c++) {
        if (aCookies[c].getName().equals(sName)) {
View Full Code Here

      String defaultValue) {
    if(cookies == null){
      return null;
    }
    for (int i = 0; i < cookies.length; i++) {
      Cookie cookie = cookies[i];
      if (cookieName.equals(cookie.getName()))
        return (cookie.getValue());
    }
    return (defaultValue);
  }
View Full Code Here

  public static Cookie getCookie(Cookie[] cookies, String cookieName) {
    if(cookies == null){
      return null;
    }
    for (int i = 0; i < cookies.length; i++) {
      Cookie cookie = cookies[i];
      if (cookieName.equals(cookie.getName()))
        return (cookie);
    }
    return (null);
  }
View Full Code Here

   * and path will be set to <code>/</code>.
   * @param res the source where the cookie will be deleted.
   * @param cookieName the name of the cookie to delete.
   */
  public static void deleteCookie(HttpServletResponse res, String cookieName){
    Cookie cookie = new Cookie(cookieName,null);
    cookie.setMaxAge(0);
    cookie.setPath("/");
    res.addCookie(cookie);
  }
View Full Code Here

                // next token
                cookieLine = nextToken(st);
            } else {
                String name = cookieLine.substring(0, equalPos);
                String value = extractFromQuotes(cookieLine.substring(equalPos + 1));
                Cookie thisCookie = new Cookie(name, value);
                thisCookie.setVersion(version);
                thisCookie.setSecure(isSecure());
                cookieList.add(thisCookie);

                // check for path / domain / port
                cookieLine = nextToken(st);
                while ((cookieLine != null) && cookieLine.trim().startsWith("$")) {
                    cookieLine = cookieLine.trim();
                    equalPos = cookieLine.indexOf('=');
                    String attrValue = equalPos == -1 ? "" : cookieLine
                            .substring(equalPos + 1).trim();
                    if (cookieLine.startsWith("$Path")) {
                        thisCookie.setPath(extractFromQuotes(attrValue));
                    } else if (cookieLine.startsWith("$Domain")) {
                        thisCookie.setDomain(extractFromQuotes(attrValue));
                    }
                    cookieLine = nextToken(st);
                }

                Logger.log(Logger.FULL_DEBUG, Launcher.RESOURCES,
                        "WinstoneRequest.CookieFound", thisCookie.toString());
                if (thisCookie.getName().equals(WinstoneSession.SESSION_COOKIE_NAME)) {
                    // Find a context that manages this key
                    HostConfiguration hostConfig = this.hostGroup.getHostByName(this.serverName);
                    WebAppConfiguration ownerContext = hostConfig.getWebAppBySessionKey(thisCookie.getValue());
                    if (ownerContext != null) {
                        this.requestedSessionIds.put(ownerContext.getContextPath(),
                                thisCookie.getValue());
                        this.currentSessionIds.put(ownerContext.getContextPath(),
                                thisCookie.getValue());
                    }
                    // If not found, it was probably dead
                    else {
                        this.deadRequestedSessionId = thisCookie.getValue();
                    }
//                    this.requestedSessionId = thisCookie.getValue();
//                    this.currentSessionId = thisCookie.getValue();
                    Logger.log(Logger.FULL_DEBUG, Launcher.RESOURCES,
                            "WinstoneRequest.SessionCookieFound",
                            new String[] {thisCookie.getValue(),
                            ownerContext == null ? "" : "prefix:" + ownerContext.getContextPath()});
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of javax.servlet.http.Cookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.