aspose file tools*
The moose likes Servlets and the fly likes alternate way for setHeader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "alternate way for setHeader" Watch "alternate way for setHeader" New topic
Author

alternate way for setHeader

kalyen kumar
Ranch Hand

Joined: Sep 18, 2008
Posts: 53
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

Joined: Jun 06, 2006
Posts: 161
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.


Error: Keyboard not attached. Press F1 to continue.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
 
wood burning stoves
 
subject: alternate way for setHeader