Package javax.servlet.http

Examples of javax.servlet.http.Cookie


          reqSessionValue = sessionCookieValue;
        } catch (IllegalStateException ise) {
        } catch (NullPointerException npe) {
        }
      } else {
        Cookie c;
        inCookies.addElement(c = new Cookie(name, value));
        if (path != null) {
          c.setPath(path);
          if (domain != null)
            c.setDomain(domain);
        }
      }
    }
View Full Code Here


            out.println();
          }
        }
        StringBuffer sb = null;
        StringBuffer sb2 = null;
        Cookie cc = null;
        // add session cookie
        if (sessionValue != null) {
          HttpSession session = serve.getSession(sessionValue);
          if (session != null) {
            if (((AcmeSession) session).isValid()) {
              if (session.isNew()) {
                cc = new Cookie(SESSION_COOKIE_NAME,
                    sessionValue);
                if (serve.expiredIn < 0)
                  cc.setMaxAge(Math.abs(serve.expiredIn) * 60);
                ServletContext sc = ((AcmeSession) session)
                    .getServletContext();
                try {
                  String cp = (String) sc
                      .getClass()
                      .getMethod("getContextPath",
                          Utils.EMPTY_CLASSES)
                      .invoke(sc, Utils.EMPTY_OBJECTS);
                  if (cp.length() == 0)
                    cp = "/";
                  cc.setPath(cp);
                } catch (Exception e) {

                }

                addCookie(cc);
              }
            } else {
              cc = new Cookie(SESSION_COOKIE_NAME, "");
              cc.setMaxAge(0);
              addCookie(cc);
            }
          }
        }

        // how to remove a cookie
        // cc = new Cookie(cookieName, "");
        // cc.setMaxAge(0);
        //
        for (int i = 0; outCookies != null && i < outCookies.size(); i++) {
          cc = (Cookie) outCookies.elementAt(i);
          if (cc.getSecure() && isSecure() == false)
            continue;
          int version = cc.getVersion();
          String token;
          if (version > 1) {
            if (sb2 == null)
              sb2 = new StringBuffer(SETCOOKIE + "2: ");
            else
              sb2.append(',');
            sb2.append(cc.getName());
            sb2.append("=\"");
            sb2.append(cc.getValue()).append('"');
            token = cc.getComment();
            if (token != null)
              sb2.append("; Comment=\"").append(token)
                  .append('"');
            token = cc.getDomain();
            if (token != null)
              sb2.append("; Domain=\"").append(token).append('"');
            if (cc.getMaxAge() >= 0)
              sb2.append("; Max-Age=\"").append(cc.getMaxAge())
                  .append('"');
            token = cc.getPath();
            if (token != null)
              sb2.append("; Path=\"").append(token).append('"');
            if (cc.getSecure()) {
              sb2.append("; Secure");
            }
            sb2.append("; Version=\"").append(version).append('"');
          } else {
            if (sb == null)
              sb = new StringBuffer(SETCOOKIE + ": ");
            else
              // sb.append(',');
              sb.append("\r\n" + SETCOOKIE + ": "); // for IE not
            sb.append(cc.getName());
            sb.append('=');
            sb.append(cc.getValue());// .append('"');
            if (cc.getDomain() != null
                && cc.getDomain().length() > 0) {
              sb.append("; domain=" + cc.getDomain());
            }
            if (cc.getMaxAge() >= 0) {
              sb.append("; expires=");
              sb.append(expdatefmt.format(new Date(new Date()
                  .getTime() + 1000l * cc.getMaxAge())));
            }
            if (cc.getPath() != null && cc.getPath().length() > 0) {
              sb.append("; path=" + cc.getPath());
            }
            if (cc.getSecure()) {
              sb.append("; secure");
            }
          }
        }
        if (sb != null) {
View Full Code Here

   * @return
   */
  public static String getDlogSessionId(HttpServletRequest req){
    //���ȴ�Cookie�л�ȡssn_idֵ
    String ssn_id = null;
    Cookie cok = RequestUtils.getCookie(req, Globals.SESSION_ID_KEY_IN_COOKIE);
    if(cok != null){
      ssn_id = cok.getValue();
    }
    if(StringUtils.isEmpty(ssn_id)){
      //���Cookie�ò�����ӷ������ĻỰ�ж�ȡ
      HttpSession ssn = req.getSession(false);
      if (ssn != null)
View Full Code Here

   * ���FCKUpload���������ɵ�Cookie
   * @param req
   * @param res
   */
  public static void clearDlogSessionId(HttpServletRequest req, HttpServletResponse res){
    Cookie cok = RequestUtils.getCookie(req, Globals.SESSION_ID_KEY_IN_COOKIE);
    if(cok != null){
      cok.setMaxAge(0);
      res.addCookie(cok);
    }
  }
View Full Code Here

   * @param value
   * @param maxAge
   */
  public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name,
      String value, int maxAge) {
    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);
    String serverName = request.getServerName();
    String domain = getDomainOfServerName(serverName);
    if(domain!=null && domain.indexOf('.')!=-1){
      cookie.setDomain('.' + domain);
    }
    cookie.setPath("/");
    response.addCookie(cookie);
  }
View Full Code Here

   * @param path
   * @param response
   */
  public static void storeCookie(String id, String value,String path,
      HttpServletResponse response) {
    Cookie cookie = new Cookie(id, value);
    cookie.setPath(path);
    response.addCookie(cookie);
  }
View Full Code Here

     * @param name the name of the cookie.
     * @return the Cookie object if it exists, otherwise null.
     */
    public static Cookie getCookie(HttpServletRequest request, String name)
    {
        Cookie cookies[] = request.getCookies();
        if (cookies == null || name == null || name.length() == 0)
        {
            return null;
        }
        //Otherwise, we have to do a linear scan for the cookie.
View Full Code Here

     * will always try to set this cookie again)
     */
    public static Cookie setCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, int maxAge, String path)
    {
        log.debug("CookieUtils.setCookie " + name + ":" + value);
        Cookie cookie = new Cookie(name, value);
        cookie.setMaxAge(maxAge);
        cookie.setPath(path);
        response.addCookie(cookie);

        return cookie;
    }
View Full Code Here

     * @param name the name of the cookie
     * @return the value of the cookie, or null if the cookie does not exist.
     */
    public static String getCookieValue(HttpServletRequest request, String name)
    {
        Cookie cookie = getCookie(request, name);
        if (cookie != null)
        {
            return cookie.getValue();
        }
        return null;
    }
View Full Code Here

            anvil.Log.log().debug("   " + key + " : " + value);
        }
        anvil.Log.log().debug("Cookies in this request");
        Cookie[] cookies = request.getCookies();
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            anvil.Log.log().debug("   " + cookie.getName() + " = " + cookie.getValue());
        }
        anvil.Log.log().debug("Auth Type: " + request.getAuthType());
        anvil.Log.log().debug("HTTP Method: " + request.getMethod());
        anvil.Log.log().debug("Path Info: " + request.getPathInfo());
        anvil.Log.log().debug("Path Trans: " + request.getPathTranslated());
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.