aspose file tools*
The moose likes Servlets and the fly likes Cookies getting lost in Internet Explorer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookies getting lost in Internet Explorer" Watch "Cookies getting lost in Internet Explorer" New topic
Author

Cookies getting lost in Internet Explorer

Arti Soni
Greenhorn

Joined: May 04, 2007
Posts: 9
Hi,
I am writing about 20 cookies using a common method through java on one of the pages and trying to read them on next page. In Internet Explorer one of the cookie is not available. There is no place in between where the cookie is getting overwritten / deleted. Also the code works perfect in mozilla but not in Explorer. The strange thins is everytime the same cookie is not available.
Can anyone please suggest what could be going wrong.

Regards Arti.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Perhaps if you showed us your cookie-setting code...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

when you say 'next page', is this in the same window or are you opening a new window? There is a known issue with some versions of IE where sessions can get lost when opening a new window, and I presume cookies are the same.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Here is a Microsoft article on limitations on cookies in MSIE
Summarized:

Microsoft Internet Explorer complies with the following RFC 2109 recommended minimum limitations: •at least 300 cookies
•at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)
•at least 20 cookies per unique host or domain name


Bill
Arti Soni
Greenhorn

Joined: May 04, 2007
Posts: 9
Hi,

The follwoing is the code where i am writing cookies -

public void createCookies(HttpServletRequest request, HttpServletResponse response, Hashtable cookieVals, int maxAge, String path, String domain){
Enumeration cookieKeys = cookieVals.keys();
System.out.println("Writing cookies.......\n");
while (cookieKeys.hasMoreElements()) {
String cookieKey = (String)cookieKeys.nextElement();
String cookieKeyVal = (String)cookieVals.get(cookieKey);
Cookie cookie = new Cookie(cookieKey, cookieKeyVal);
System.out.println("key " + cookieKey);
System.out.println("Value " + cookieKeyVal);
cookie.setPath(path);
//cookie.setDomain(domain);
cookie.setMaxAge(maxAge);
cookie.setVersion(1);
response.addCookie(cookie);
}
}

In the above code, the hashmap contains the name value pairs of the cookies being written and the maxAge variable being passed is -1.

The next page is getting loaded in the same window and not a new window.

Also the values that are being written in the cookies are just code values so are not too large and also the maximum number of cookies being written is not more than 25.

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What's the name of the missing cookie ?


[My Blog]
All roads lead to JavaRanch
NareshA WaswaniA
Greenhorn

Joined: Feb 26, 2007
Posts: 9
in internet explorer, you can have at the max 20 cookies from one host.

that is he main reason. i think the cookies are getting more than 20.

+91-9986461501
Arti Soni
Greenhorn

Joined: May 04, 2007
Posts: 9
Is it documented somewhere that there can be only 20 cookies in IE ? Also the cookies that get lost are not the last ones in the hashmap.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
Is it documented somewhere that there can be only 20 cookies in IE ?

William was so kind to include a link to the relevant documentation in his post.

Also the cookies that get lost are not the last ones in the hashmap.

Since it is not guaranteed that more than 20 will be supported, trying to guess which ones beyond that will be ignored is just idle speculation.

I'd question any design that relies on this many cookies to begin with. Can you tell us why you think that's necessary?
Arti Soni
Greenhorn

Joined: May 04, 2007
Posts: 9
The content for the page is to be picked up from Documentum and since that reads cookies all the data had to be transferred from request/hidden fields to the Cookies.
NareshA WaswaniA
Greenhorn

Joined: Feb 26, 2007
Posts: 9
And what if the cookie is not supported. In that case will your application not work.

And more over in the case of cookies, you never know the way the cookies are sent : in which order. So even if the end cookies in the hasmap are not missing, quiet possible that they are going in the starting of the sequence. So you never know the exact sequence.

+91-9986461501
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I believe that an applications main feature should not be built around cookies.Not , at least for a completely web based applications , where you do not know the settings of the browser that the client might be using.But there are few other stuffs to look at for tracking client sessions.

But its fine for web based products as products will have a system requirement where the vendor might say that for running this application cookies must be allowed.


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookies getting lost in Internet Explorer