List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:com.threewks.thundr.http.Cookies.java
/** * Gets all cookies of the given name from the request * /*from w w w. j ava 2 s . c o m*/ * @param name * @param req * @return */ public static final List<Cookie> getCookies(String name, HttpServletRequest req) { List<Cookie> results = new ArrayList<Cookie>(); if (req.getCookies() != null) { for (Cookie cookie : req.getCookies()) { if (cookie.getName().equals(name)) { results.add(cookie); } } } return results; }
From source file:net.bluehornreader.web.WebUtils.java
public static String cookieAsString(Cookie cookie) { StringBuilder bld = new StringBuilder(); bld.append("Name=").append(cookie.getName()).append(" "); bld.append("Value=").append(cookie.getValue()).append(" "); bld.append("Domain=").append(cookie.getDomain()).append(" "); bld.append("MaxAge=").append(cookie.getMaxAge()).append(" "); bld.append("Path=").append(cookie.getPath()).append(" "); bld.append("Secure=").append(cookie.getSecure()).append(" "); bld.append("Comment=").append(cookie.getComment()).append(" "); bld.append("Version=").append(cookie.getVersion()).append(" "); return bld.toString().trim(); }
From source file:com.flexive.war.filter.FxRequestUtils.java
/** * Get the cookie with the given name. Returns null if no such cookie is defined. * * @param request the current request//from w w w.j a v a 2s . co m * @param name the name of the cookie (case-sensitive) * @return the cookie with the given name, or null if no such cookie is defined. */ public static Cookie getCookie(HttpServletRequest request, String name) { final Cookie[] cookies = request.getCookies(); if (cookies == null || name == null) { return null; } for (Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return cookie; } } return null; }
From source file:nl.strohalm.cyclos.utils.RequestHelper.java
/** * Finds a cookie with the given name, returning null when it's not found *//*from w ww .j a v a 2 s . c o m*/ public static Cookie getCookie(final ServletRequest servletRequest, final String name) { final HttpServletRequest request = (HttpServletRequest) servletRequest; final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie; } } } return null; }
From source file:com.netease.channel.util.LoginUtil.java
/** * cookie???(,?)//from www .jav a 2 s. c o m * * @param request * @return */ public static String getLoginStatus(final HttpServletRequest request) { Cookie ntesCookie = null; String username = null; String encodedUserName = null; Cookie[] cookies = request.getCookies(); // ? cookies ? NULL 0 if (cookies != null && cookies.length > 0) { // ?? cookies for (Cookie cooky : cookies) { // cookies ?? String cname = cooky.getName(); // cookies ?? NTES_SESS if ("NTES_SESS".equals(cname)) { ntesCookie = cooky; // cookies ??? encodedUserName = ntesCookie.getValue(); // ?? ntescode ntes = new ntescode(); // ????? int ret = ntes.validate_cookie(encodedUserName.getBytes(), 8, PERSISTENTTIME, true); // ????? if (ret >= 0) { username = new String(ntes.ssn); if (username.indexOf("@") <= 0) { username += "@163.com"; } } else { username = ""; } } } // NTES_SESS???passport? // ?pinfo // 1cookie?pinfo??2 String encodedPassport; if (StringUtils.isEmpty(username)) { try { for (Cookie cooky : cookies) { if ("NTES_PASSPORT".equals(cooky.getName())) { ntesCookie = cooky; // cookies ??? encodedPassport = ntesCookie.getValue(); // ?? ntescode ntes = new ntescode(); // ?????,ret>0pinfo?? // 1,false??cookie int ret = ntes.validate_persistent_cookie(encodedPassport.getBytes(), 8, PERSISTENTTIME, true); if (ret >= 0) { username = new String(ntes.ssn); if (username.indexOf("@") <= 0) { username += "@163.com"; } } } } } catch (Exception ex) { } } } return username; }
From source file:org.alfresco.web.app.servlet.LanguageCookieFilter.java
public static Cookie getCookie(ServletRequest request, String name) { if (((HttpServletRequest) request).getCookies() != null) { for (Cookie cookie : ((HttpServletRequest) request).getCookies()) { if (cookie.getName().equals(name)) { return cookie; }/* w ww .ja v a 2 s . co m*/ } } return null; }
From source file:io.lavagna.web.helper.UserSession.java
private static Cookie getCookie(HttpServletRequest request, String name) { if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if (cookie.getName().equals(name)) { return cookie; }/* w w w . jav a2 s . com*/ } } return null; }
From source file:cn.vlabs.duckling.vwb.VWBFilter.java
private static String getLocaleString(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals("Portal.Locale")) { return cookie.getValue(); }//from www. j a v a 2 s . co m } } return null; }
From source file:org.craftercms.core.util.HttpServletUtils.java
public static Cookie getCookie(String name, HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (ArrayUtils.isNotEmpty(cookies)) { for (Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie; }/* www .java 2s . com*/ } } return null; }
From source file:com.baidu.rigel.biplatform.ma.auth.resource.RandomValidateCode.java
/** * //from w w w. j a v a2 s . c om * @param request * @param response * @param cacheManagerForResource */ public static void getRandcode(HttpServletRequest request, HttpServletResponse response, CacheManagerForResource cacheManagerForResource) { // BufferedImageImage,Image???? BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics g = image.getGraphics(); // ImageGraphics,????? g.fillRect(0, 0, width, height); g.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18)); g.setColor(getRandColor(110, 133)); // for (int i = 0; i <= lineSize; i++) { drowLine(g); } // ? String randomString = ""; for (int i = 1; i <= stringNum; i++) { randomString = drowString(g, randomString, i); } String key = null; if (request.getCookies() != null) { for (Cookie tmp : request.getCookies()) { if (tmp.getName().equals(Constants.RANDOMCODEKEY)) { key = tmp.getName(); cacheManagerForResource.removeFromCache(key); break; } } } if (StringUtils.isEmpty(key)) { key = String.valueOf(System.nanoTime()); } cacheManagerForResource.setToCache(key, randomString); final Cookie cookie = new Cookie(Constants.RANDOMCODEKEY, key); cookie.setPath(Constants.COOKIE_PATH); response.addCookie(cookie); g.dispose(); try { ImageIO.write(image, "JPEG", response.getOutputStream()); // ?? } catch (Exception e) { LOG.info(e.getMessage()); } }