Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arguments being switched around and disappearing?

Status
Not open for further replies.

Ito2233

MIS
Sep 2, 2003
77
0
0
US
In my code I have a drop-down menu that redirects and sets a cookie. The value of one of the options selected is the following:

Code:
<option value="<isa:webappsURL name=&quot;/b2b/init.do&quot;/>?shopId=COMPANY&<%= request.getQueryString() %>">United States</option>

Redirection works when clicking GO! But when I'm setting the cookie, something strange happens. First, this is what the above chosen value looks like when passed to the server:

Code:
/b2b-playground/b2b/init.do;jsessionid=ID4001DB0.9722336212
620123End;sap2ee_*=4001?shopId=COMPANY&null

Some data is added to the above string, using Javascript, to make a cookie string:

Code:
var expiration = new Date("December 1, 2004");
expiration = expiration.toGMTString();
test = "name=" + menuvalue + ";expires=" + expiration;

The value of variable TEST ends up looking like this:

Code:
name=/b2b-playground/b2b/init.do;jsessionid=ID4001DB0.9722336212
620123End;sap2ee_*=4001?shopId=COMPANY&null;expires=Wed, 1 Dec 2004 05:00:00 UTC

Now HERE IS THE CURIOUS PART...when variable TEST gets assigned to document.cookie using Javascript, the value of document.cookie ends up being:

Code:
name=/b2b-playground/b2b/init.do;sap2ee_*=4001; JSESSIONID=ID4001DB0.9520725885913588End

So my question is Where did the "?shopID=COMPANY&null" part go, and why did the order of the arguments change? When redirection is attempted after reading this cookie, it fails, and I suspect it's because the full cookie string is not being assigned to document.cookie. I parse everything correctly and assign the string to window.location, but redirection fails. Can someone tell me why the string is being cut off?
Thanks
 
I believe the problem is the "?" character in URL value. i

i.e.

name=/b2b-playground/b2b/init.do;jsessionid=ID4001DB0.9722336212
620123End;sap2ee_*=4001?shopId=COMPANY...

which breaks the cookie string. Try encode the URL before putting it in the cookie.
 
Hmmmm...sounds like a good suggestion, but I'm confused. At which point should I be ESCAPING and UNESCAPING the string?
Should I escape it before storing it in document.cookie, as below?
Code:
document.cookie = escape(test);

Then at which point do I unescape it? When I assign the
window.location the URL string, should it be encoded?

Also, how would I go about encoding the question mark?
Thanks
 
Use the java.net.URLEncoder & java.net.URLDecoder classes ...

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top