Java setting cookies, storing and reading __java storage cookies

Source: Internet
Author: User
	"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "," "" "", "" ""/**
	Requestmapping (value= "default_axis.jspx") public
	String Setdefault_doctree (httpservletrequest request, HttpServletResponse response,httpsession session) {
		Requestproxy proxy = requestproxy.fromrequest (request);
		This sets the default tree
		Cookie Defaultcookie = null;
		String Defaultaxisid = Proxy.getchineseparameter ("Defaultaxisid");
		if (! Stringutil.isempty (Defaultaxisid)) {
			Tadminuser user = (Tadminuser) session.getattribute (global.session_user_ NAME);
			if (user!= null) {
				Defaultcookie = new Cookie (User.getid (). toString (), defaultaxisid);
				Defaultcookie.setpath ("/");
				Defaultcookie.setmaxage (365*24*24*60);
				Response.addcookie (Defaultcookie);
			}
		return "redirect:doc_tree.jspx";
	}


The name of the cookie can be a dynamic value.

Defaultcookie = new Cookie (User.getid (). toString (), defaultaxisid);

cookie[] cookies = request.getcookies ();
		"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "OldValue
		list 


				String val = "";  "" "" "" "" Here is another way to store "" "" "" "" ""

				if (oldvalue!=null &&!oldvalue.equals (")) {
					val = oldValue +"; " + Hotelinfo.gethotel (). GETS_HOTELCD () + "*" +hotelinfo.gethotel (). Gets_hotel ();
					val = Urlencoder.encode (val, "UTF-8");
				} else{
					val = Hotelinfo.gethotel (). GETS_HOTELCD () + "*" +hotelinfo.gethotel (). Gets_hotel ();
					val = Urlencoder.encode (val, "UTF-8");
				}
				Cookie cookie = new Cookie ("Hotel_name_id_cookie", Val);
				Cookie.setpath ("/");
				Cookie.setmaxage (365 * * *);
				Response.addcookie (cookie);   Be sure to add, otherwise you can't read or null when you read it.






							String val = "";
				if (Oldvalue!=null &&!oldvalue.equals ("")) {
					val = oldValue + ";" + Hotelinfo.gethotel (). GETS_HOTELCD () + "*" +hotelinfo.gethotel (). Gets_hotel ();
					val = Urlencoder.encode (val, "UTF-8");
				} else{
					val = Hotelinfo.gethotel (). GETS_HOTELCD () + "*" +hotelinfo.gethotel (). Gets_hotel ();
					val = Urlencoder.encode (val, "UTF-8");
				}
				Cookie cookie = new Cookie ("Hotel_name_id_cookie", Val);
				Cookie.setpath ("/");
				Cookie.setmaxage (365 * * *);
				Response.addcookie (cookie);   Be sure to add, otherwise you can't read or null when you read it.


The name of the cookie can be a dynamic value. The name of the cookie can be a dynamic value.


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.