Click to See Complete Forum and Search --> : servlet cookie to JavaScript cookie??


BarmyYeTTi
06-08-2005, 12:17 PM
I might be doing all this wrong, so please point it out if I am.

I have a servlet login screen that creates user cookies as below:

"Cookie acco = new Cookie("account",java.net.URLEncoder.encode(rs.getString("login.accountnumber"),"UTF-8"));"

As you can see the value is taken from a database.
There is also other info. passed, address details etc.

The details are passed so that when they are further into the site they can click an icon and autofill a form with their details... I know it may sound stupid but it is required.

On the page that decodes the cookie I have the following code:
"<script LANGUAGE="JavaScript" type="text/javascript">
function getCookie(name){
var cname=name+"=";
var dc = document.cookie;
if(dc.length>0){
begin = dc.indexOf(cname);
if(begin != -1) {
begin += cname.length;
end=dc.indexOf(";",begin);
if(end ==-1) end=dc.length;
return dc.substring(begin,end);
}
}
return null;
}

function setSender(text){
document.forms[0].sname.value=unescape(text);
}
</script>"

using the following text "Unit 2, Langley Business Park"

The problem I have is that the cookie is encoded by the servlet into the following format:
"Unit+2%2C+Langley+Business+Park"

but when decoded by the javascript I get the following:
"Unit+2,+Langley+Business+Park"

I have scoured the net for hours looking for an answer but am unable to find anything.

If someone could please help me decode the string back without the '+' signs I would be very greatful.

Cheers
Elliot