Set cookie in Java:
Public static void setcookie (string cookiename, string value,
Int expirehours ){
Httpservletresponse response = servletactioncontext. getresponse ();
Cookie = new cookie (cookiename, value );
Cookie. setpath ("/"); // you need to set this
Cookie. setdomain (".bessystem.com"); // you can use this setting to share two websites.
If (expirehours! = 0 ){
Expirehours = expirehours * 60*60; // if this parameter is not set, cookies are not written into the hard disk, but in the memory. They are only useful on the current page. If the unit is seconds, refresh the page, the cookie cannot be found,
}
Cookie. setmaxage (expirehours );
Response. addcookie (cookie );
}
Get cookie in HTML:
function getCookie(c_name){if(document.cookie.length>0){ c_start=document.cookie.indexOf(c_name + "="); if(c_start!=-1){ c_start=c_start + c_name.length+1 ; c_end=document.cookie.indexOf(";",c_start); if(c_end==-1) { c_end=document.cookie.length; } return unescape(document.cookie.substring(c_start,c_end)); }}return "";}
Get the cookie name defined in the background in JS and get the value through name
<SCRIPT>
VaR username = getcookie ("username ");
Alert (username );
</SCRIPT>