How can I set response.setHeader so that it will not start download the files if the files are not supported to display in the browser
code. JSP file to use the servlet that dispay the content in the iframe
From the above code i am able to view pdf, png audio, video, but some unsupported files like docx, zip, rar are start downloading. so what should i edit in the code so that it will not start downloading.
And my audio or video files get start play on loading page, they should not be start automatically.
sorry for my weak english.
There's two problems with that. First of all your servlet will have no way of knowing whether the user's browser is configured to display files of a particular MIME type or not. And second, what do you want to do instead of "starting to download automatically"? The only other option I can think of is to return something other than 200 as the response code, but you'd have to find a suitable code which can explain why you aren't going to download the file.
posted 1 year ago
I want to show error message if the browser is not able to display the file.
Jitender Mandhaniya wrote:I want to show error message if the browser is not able to display the file.
As Paul already said, there really is no way for the server to know what the rendering capabilities are of the browser. The browser knows, and there is a mechanism for the browser to inform the server, but typically browsers tell the server they support everything.
The HTTP Accept header presented by the browser should detail the types of content it will accept (and be able to render), and if the information provided by the browser was actually accurate, the server could use this information to decide what type of content to return. But unfortunately, browsers usually include a wildcard of */*, indicating that they will accept all content types, so the server really cannot make an informed decision.
Here an example of a request from my Chrome browser:You can see that the Accept header includes */*
Specialized clients, like web service clients are usually a lot better at really indicating what they can use:
Browsers will always "accept" PDF files, as far as I know. But whether they will accept a PDF file and then display it or whether they will accept it and just store it somewhere temporarily, or ask the user where it should be stored permanently, only the browser knows for sure.
I have to say I don't understand the reason behind this requirement. If you're designing a server then it's really none of your business what the user does with a downloaded file.