Java-cookie Tool Class

Source: Internet
Author: User

Package Com.gordon.utils;import Javax.servlet.http.cookie;import Javax.servlet.http.httpservletrequest;import  javax.servlet.http.httpservletresponse;/** * Cookie Tool class * */public class Cookieutil {/** * Add cookie * * @param response * @param name * @param value * @param maxAge */public static void Addcookie (HttpServletResponse response, String name, Stri Ng value) {Cookie cookie = new Cookie (name, value); Cookie.setpath ("/"); Response.addcookie (cookie);} /** * Add Cookie * * @param response * @param name * @param value * @param maxAge */public static void Addcookie (Httpservle  Tresponse response, String name, string value, int maxAge) {Cookie cookie = new Cookie (name, value); Cookie.setpath ("/"); if (MaxAge > 0) {cookie.setmaxage (maxAge);} Response.addcookie (cookie);} /** * Delete Cookie * * @param response * @param name */public static void Removecookie (HttpServletResponse response, String n AME) {Cookie UID = new Cookie (name, null); Uid.setpath ("/"); uid.setmaxage (0); Response.addcookie (UID);} /** * GetCookie value * * @param request * @return */public static string Getuid (HttpServletRequest request, string cookiename) {cookie Cookies[] = Request.getcookies (); for (Cookie cookie:cookies) {if (Cookie.getname (). Equals (CookieName)) {return Cookie. GetValue ();}} return null;}}

Java-cookie Tool Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.