Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem w/ HTTP Cooke header

0 views
Skip to first unread message

jboschen

unread,
Aug 18, 2005, 2:26:58 PM8/18/05
to
We have pages that are submitted via an applet, with cookies which have no
value. The HTTP Cookie header ends up looking like the following:

Cookie: COOKIE1; COOKIE2=abc

In a CFML page we process the cookies but are getting the following exception
when attempting to access the values of cookies which have been submitted
without a value:

Element COOKIE1 is undefined in a Java object of type class
coldfusion.runtime.CookieScope referenced as The error occurred on line 4.

The following is a CFML example that will reproduce this behavior:
<CFSCRIPT>
cScope = Evaluate('COOKIE');
for ( sField in cScope ) {
WriteOutput(sField & '=' & cScope[sField]);
}
</CFSCRIPT>

If however, the HTTP Cookie header is formatted as follows, CF does not have a
problem retrieving its value, even though that value is empty.

Cookie: COOKIE1=; COOKIE2=abc

To me it seems that if CF is able to report that a field exists within a
collection, such as from the statement for ( sField in cScope ) {, then it
should also not have an issue accessing the same field.

Is this defined behavior?

Thanks in advance,
Jeremy

mxstu

unread,
Aug 20, 2005, 3:20:50 PM8/20/05
to
There is a difference between an empty value and a null value. If a key's value
is an empty string, that value still exists to CF and can be accessed by like
any other value.

<!--- an empty string is a valid value --->
<cfset myVariable = "" />

If the key's value is null, it "essentially" does not exist to CF and so it
throws an undefined error when you try to access it. Try using IsDefined() to
determine whether or not the key's value is null.

Are you asking why the behavior is different than with regular structures?

BKBK

unread,
Aug 20, 2005, 5:13:11 PM8/20/05
to
>... it seems that if CF is able to report that a field exists within a
collection...
>... it should also not have an issue accessing the same field.
I suspect that Coldfusion, like the Java underneath, accesses such structures
as name-value pairs, in the form name=value.


mxstu

unread,
Aug 20, 2005, 9:41:00 PM8/20/05
to
>I suspect that Coldfusion, like the Java underneath, accesses such structures
>as name-value pairs, in the form name=value.

"COOKIE" is not a true CF structure (ie. object created with StructNew()), so
the behavior is a bit different.

Java collections use key/value pairs. In this situation the "key" (COOKIE1)
exists, but the key's "value" is null because it was not explicitly set to an
empty string as it was in the second statement.

Cookie: COOKIE1=; COOKIE2=abc


0 new messages