This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Browser not supplying cookie data in request  RSS feed

 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Our web application requires that a user logs in. This sets a cookie in all headers subsequently sent from the browser that contains the session id. This is how I determine if a user has logged in. If the header does not contain a session cookie then I redirect them to the login page.

Problem now is that I have a servlet that sends back a .xls file. The browser asks the user if they want to open or save the .xls file. If they choose 'open' the request does not have the cookie value set and they end up seeing my login page rendered as HTML in the excel file instead.

Has anyone had this problem before? What can I do to ensure that the browser sends the cookie in this request from the 'question dialog'. I did not expect this situation.

Thanks, Jared.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds odd. The "File Open" dialog does not send a request. It is opened after the response has been received, and no further requests or responses between browser and server take place afterwards.

Apparently there's something inside of the XLS file that causes a request to be sent. That's out of the control of the browser, and consequently it's unlikely that any cookie would be sent along with it, ever.
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Originally posted by Ulf Dittmer:
This sounds odd. The "File Open" dialog does not send a request. It is opened after the response has been received, and no further requests or responses between browser and server take place afterwards.


Exactly what I thought -- odd. However a second request to the same servlet is taking place after the first request arrives back though. I can see this when debugging in eclipse (and this request doesn't have any cookies set). I'll have a look at what the excel file has included in it. Maybe the problem is something obvious.

Thanks, Jared.

[ January 06, 2008: Message edited by: Jared Cope ]
[ January 06, 2008: Message edited by: Jared Cope ]
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Alright finally figured this one out. Seems IE will pass the URL through to Excel and it is Excel that is making the second request. Firefox instead will pass the document through to excel for display instead. So IE would appear to do 2 requests, Firefox only one.

I have fixed this by modifying the header content type to the following instead:



This will make IE pass the downloaded file through to excel as I wanted. Hope this will help someone else.

Cheers, Jared.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!