File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Cookies not getting stored in IE6 and IE7 when running in environment resembling production Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookies not getting stored in IE6 and IE7 when running in environment resembling production" Watch "Cookies not getting stored in IE6 and IE7 when running in environment resembling production" New topic
Author

Cookies not getting stored in IE6 and IE7 when running in environment resembling production

Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Hi All,

I have an application where I have to set cookies.
The cookies are getting set in Firefox. But it doesnt for IE6 and IE7.

Funny thing is that it works when I run the code on my localhost. But when I move the code to an environment resembling the production it doesnt work.

Below is the code I use to set cookies:



Am I missing something here or is there some other setting that I need to do in the other environment.
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

This is a shot in the dark - but is it a security issue in IE? IE will likely apply different security settings when making requests of "localhost" than it would on a non-local system, such as your production (-like) environment.


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Thanks for your reply Pete.

However, I dont think its an IE security issue. Since cookies are being stored by othe websites on the internet.
Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
I checked the Temporary Internet Files folder.
I dont see the cookie getting stored itself when running from the production like environment.

Also I was looking at the response headers using Fiddler from my localhost and the production like environment.



LOCALHOST
-----------------------------
GET http://localhost:8180/MyApp/general/home HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://localhost:8180/MyApp/general/beforeHome;jsessionid=57AA4D83D6039FD1D78BCAA8DD62B207
Accept-Language: en-us
Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; MS-RTC LM 8; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: localhost:8180
Pragma: no-cache
Cookie: testcookie=yes; ; JSESSIONID=57AA4D83D6039FD1D78BCAA8DD62B207; myCookie=asd?asd?12323


PROD LIKE ENVIRONMENT
-----------------------------------------------
GET http://dev.myapp.com/MyApp/general/home HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Pragma: no-cache
Accept-Language: en-us
Cookie: testcookie=yes; ; JSESSIONID=EC5039DB3226E3E188D7716C051C7E36.app_node1; myCookie="asd?asd?12323"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; MS-RTC LM 8; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: dev.myapp.com
Connection: Keep-Alive
Cache-Control: no-cache





They both look the same, except that for the production like environment the cookie details are shown within a pair of quotes " " .
Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Hi All,

I am using Fiddler to see the request and response headers.

I see that for IE the max age of the cookie is getting set as -1 even though it is explicitly set to a positive value in the code.
However, for firefox the positive value remains intact.

I am not doing any different coding based on the browser.
Todd Buell
Greenhorn

Joined: May 31, 2005
Posts: 21
I saw something that might be relevant to your problem when looking over the Cookie API. I'm not sure if the browsers are identical and configured the same on both your environments but it's worth being mindful of this when working with cookies.

[url]
http://download.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html#setValue(java.lang.String)[/url]
API wrote:With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons.


Looking at your value from the traces you provided the value does contain '?'. It could be that IE is finicky about this where FF is a bit more forgiving.


Anoop Nair wrote:I see that for IE the max age of the cookie is getting set as -1

Did I overlook where you see that? It might be that IE has some setting that does this. I'd suggest looking at the IE settings under 'Tools'->'Internet Options'->'Privacy' tab. Look over the description and see if your cookies do/don't match what the criteria there are specified to be. It could be that since the localhost falls under a different zone (to IE, see 'Security' tab) that the cookie handling is different and that your cookie could some how vary from others on the Internet.

Just some thoughts. Hope they help.

- Todd
Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Hi Todd,

Thanks for the reply and solution.

That did work. I replaced the "?" in the cookie value with "_".
Now IE6 stores cookies.

But I am stuck with something else now. There is one other place in our application where we store cookies as well.
In the login part, the login name of the user (its an email id) is stored as a cookie so that they dont have to enter it everytime they visit the site.

Problem is that email id contains "@".

Any suggestions on how this can be implemented ??
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
I do not see what the problem is. Just do with @ sign the same you did with question mark. Replace it with something else (with a special character that is allowed or with some more complicated string value) and then change it back to @ sign before you use the email address.

Or did I not understood something?
Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Hi All,

Thanks for your replies.

I am using the below code snippet to get rid of special characters:



And while retrieving the cookie value i am doing


The issue is resolved now.
david meng
Greenhorn

Joined: Sep 17, 2007
Posts: 4
good question and good solution, I just mark this for later review. tks all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookies not getting stored in IE6 and IE7 when running in environment resembling production