Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

alternate way for setHeader

 
kalyen kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to download a file from my application, i am using setContentType and setHeader....as

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-dissposition","attachment;filename=filename.xls");


can anyone help me with other ways of doing this because the above method requires the user to make browser settings and i see it doesn't work for some browsers.

Thanks in advance
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would you be able to attempt to determine the browser type the user is using
(such as somewhere else, where you do have a request object, doing a request.getHeader("user-agent"), using the heuristics for what values are found, and storing the result into the user's session.

then with that browser-specific knowledge available to the download spot, it can do if ( browser type == ...) and provide the specific use and values of the content type response headers to make the browser happy.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than make browser-specific code, which will be difficult at best, and nearly impossible to maintain with versions of browsers coming out all the time with different behaviors, I think it would be important to know what problems the headers are actually giving? What is the desired capability? What is happening?

The headers you posted are the standard ones (except with a spelling mistake for Content-Disposition) and should work as per client-expectations (they are, after all the ones that set up their browser, and should be the ones that define how their browsers work). Fooling with client-expectations can be annoying to the client and fragile to your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic