Data AccessCore JavaApp FrameworksViewTestingBuildingDeploymentDev ToolsSecurityOpinions

Thursday, September 24, 2009

How to Post a SaveAs Dialog

To prompt a 'Save As' dialog box when downloading a file, set the Content-Disposition to 'attachment' in the HTTP header.

Read RFC 2183

You can also pre-set the saved filename by setting the filename parameter as well.

Be sure to set the appropriate MIME type or content type as well.

Below is a code example of how this would be achieved in a java servlet before committing the response.

response.setContentType( "application/pdf" );
response.setHeader("Content-disposition","attachment; filename=" + "Example.pdf" );

Hope this helps, if it does, help me out by clicking on one of my sponsors.

3 comments: