Reputation: 10151
I was trying to implement this: http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx
The problem is, I have a page with url: localhost/portal/myapp
, dynamically, on that page I generate a form with action
attribute equals to localhost/servlet/myapp/generatexls
, so I'm setting a cookie in a servlet that handles that url. The thing is, I later try to read my cookie from javascript in my original page on localhost/portal/myapp
, but I can't. If while setting cookie a path equals to /
, then happily I can read it. So, the question is, why without setting a path to /
my cookie can't be read on original url, and why it matters and what's wrong with cookie if path isn't set to /
, does it implicitly set to form's action parameter? (/servlet/myapp/generatexls
) and that's why I can't read it?
Upvotes: 0
Views: 714
Reputation: 109547
Do buff.writeTo the output stream last!
The header settings only work when still nothing is written to the response. As headers are written first.
Questionable: file.close() missing, does all get written. outStream.close() maybe better not done. Maybe cookie.setPath("/")
Nicer would be if there was a file.length() for setting the content length header, and do file.writeTo the response output stream.
Upvotes: 1