Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get in java value of a cookie that was created in javascript?
    primarykey
    data
    text
    <p>I created a cookie in javascript, but when I try to get the value in java I get the previous value - the cookies hasn't refresh. is there any way to refresh the cookies so that I will get the correct value? that is the javascript:</p> <pre><code>&lt;script&gt; function setCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else { var expires = ""; } document.cookie = name+"="+value+expires+"; path=/"; alert (value); } function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i&lt;ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function del_cookie(name) { document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;'; } $j(document).ready(function(){ // remove all click-events from header_nav_submenu $j(".header_nav_submenu").unbind('click'); $j(".header_nav_submenu").click(function(){ var goHref = $j(this).attr('href'); del_cookie("last_page_nav"); alert(getCookie("last_page_nav")); setCookie("last_page_nav", goHref.substring(7), 7); alert(getCookie("last_page_nav")); }); }); &lt;/script&gt; </code></pre> <p>and that is how I try to get the value from the cookie in java:</p> <pre><code>if(FriendlyURLUtil.getFriendlyURL(request.getServerName())==null){ Cookie[] cookies = ((HttpServletRequest) request).getCookies(); for(int i = 0; i &lt; cookies.length; i++) { if (cookies[i].getName().equals("last_page_nav")) { System.out.println("The days " + cookies[i].getMaxAge()); System.out.println("The cookie says " + cookies[i].getValue()); ((HttpServletResponse) response).sendRedirect(cookies[i].getValue()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload