<p>My application needs to store the users email address in a cookie so that I can pre-populate a login form <code>(username == email address)</code>. I set the cookie value in JavaScript. If I read it from JavaScript, I get <code>foo@bar.com</code>. If I look at it in the cookie viewer in Firefox I get <code>foo@bar.com</code>.</p>

<p>When I try to read it on the server-side in Java however, I only get <code>foo</code>. </p>

<p>Do I need to do some sort of encoding/decoding here? If so, how do I do it in a way that can be decoded by both JavaScript and Java? </p>

<p>Thanks in advance!
-Michael</p>

You need to escape the value part of your cookie.
```
```
document.cookie = name + "=" +escape( value ) 
    + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" )
    + ( ( path ) ? ";path=" + path : "" ) 
    + ( ( domain ) ? ";domain=" + domain : "" ) 
    + ( ( secure ) ? ";secure" : "" );
```
```