`

Content-disposition

阅读更多

Content-disposition 是 MIME 协议的扩展,MIME 协议指示 MIME 用户代理如何显示附加的文件。Content-disposition其实可以控制用户请求所得的内容存为一个文件的时候提供一个默认的文件名,文件直接在浏览器上显示或者在访问时弹出文件下载对话框。


格式说明:

content-disposition = "Content-Disposition" ":" disposition-type *( ";" disposition-parm )  



字段说明:

Content-Disposition为属性名

disposition-type是以什么方式下载,如attachment为以附件方式下载

disposition-parm为默认保存时的文件名。


转自:http://blog.csdn.net/Nonetracer/archive/2009/02/24/3930898.aspx
在进行Web开发时,可能遇到遇到以下几种需求:
l          希望某类或者某已知MIME 类型的文件(比如:*.gif;*.txt;*.htm)能够在访问时弹出“文件下载”对话框。
l          希望客户端下载时以指定文件名显示。
l          希望某文件直接在浏览器上显示而不是弹出文件下载对话框。
对于上面的需求,使用Content-Disposition属性就可以解决。下面是代码示例:
response.setHeader("Content-disposition", "attachment;filename=" + fileName)。
//Content-disposition为属性名。
//attachment表示以附件方式下载。如果要在页面中打开,则改为inline。
//filename如果为中文,则会出现乱码。解决办法有两种:
//1、使用fileName = new String(fileName.getBytes(), "ISO8859-1")语句
//2、使用fileName = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)语句
分享到:
评论

相关推荐

    content-disposition-parser:解析内容处置HTTP标头

    $ npm install content-disposition-parser 用法 const parser = require ( 'content-disposition-parser' ) parser ( 'content-disposition: inline; filename=example.pdf' ) //-> { filename: 'example.pdf', ...

    content-disposition:创建并解析HTTP Content-Disposition标头

    内容倾向 创建并解析HTTP Content-Disposition标头安装$ npm install content-dispositionAPI var contentDisposition = require ( 'content-disposition' )contentDisposition(文件名,选项) 使用给定的文件名...

    header中Content-Disposition的作用与使用方法

    本文章详细的介绍了关于php header中Content-disposition用法详细,有需要了解header用法的朋友可参考一下

    Content-Disposition使用方法和注意事项

    最近不少Web技术圈内的朋友在讨论协议方面的事情,有的说web开发者应该熟悉web相关的协议,有的则说不用很了解。...本文我们来说一下MIME 协议的一个扩展Content-disposition。 我们在开发web系统时有时会有以下需求

    将数据导出到Excel

    将数据导出到Excel源代码及方法:response.setContentType("application/vnd.ms-... response.addHeader("Content-Disposition", "attachment;filename=logininfo.xls"); String name = request.getParameter("name");

    bug-chromium-pdf-content-disposition-encoding

    bug-chromium-pdf-content-disposition-encoding

    nginx文件强制下载的配置方法

    添加头信息Content-Disposition “attachment;”会使浏览器强制下载: 代码如下: #表示浏览器内嵌显示一个文件 Content-disposition: inline; filename=foobar.pdf   #表示会下载文件,如火狐浏览器中 Content-...

    http/formdata

    Content-Disposition: form-data; name=“projectName” testProject ----------------------------904587217962624105581666 Content-Disposition: form-data; name=“clientName” aaa ------------------------...

    PHP附件下载中文名称乱码的解决方法

    分享给大家供大家参考,具体如下: ... 此时就需要对标题进行编码,也就是说先进性urlencode,然后再放入...网上说,在RFC2231的定义里面, 多语言编码的Content-Disposition应该这么定义: 复制代码 代码如下:Content-

    2021科教版4下测试卷.pdf

    2021科教版4下测试卷.pdf

    cgi实现下载文件

    使用cgi代码在网页上实现文件的下载功能。

    ( response.setHeader()下载中文文件名乱码

    ( response.setHeader()下载中文文件名乱码问题

    gradle-6.7-bin.zip

    gradle-6.7-bin.zip 分享了,官网站下载的下载地址: https://dl-download.csdn.net/down11/20190419/11e97afb8a4c05a6f253270eecc9f3a7.zip?response-content...

    下载文件个别浏览器文件名乱码解决办法

    代码如下: if (context.Request.UserAgent.ToLower().IndexOf(“msie”, System.StringComparison.Ordinal) > -1)//IE浏览器 { context.Response.AddHeader(“content-disposition”, “filename=” + ...

    java 编写文件上传类简单易用

    其中 PARSE 部分是对每一个数据段进行解码的方法,考虑到 Content-Disposition 等属性,首先定义一个 String 数组 String[] tokens={"name=\"", "\"; filename=\"", "\"\r\n", "Content-Type: ", "\r\n\r\n" ...

    Struts2实现的多文件上传例子

    NULL 博文链接:https://hdxiong.iteye.com/blog/338026

    phantomjs-2.1.1-windows.zip

    windows版本通用工具,在官网下载巨慢总断的可以在这里下载。此工具可以爬取js渲染的页面,值的拥有。官网链接:...content-disposition=attachment%3B%20filename%3D%22phantomjs-2.1.1-windows.zip%22

    libsnappy 1.1.3版本

    libsnappy已编译过的二进制文件 源码为 1.1.3版本 ...content-disposition=attachment%3B%20filename%3Dsnappy-1.1.3.tar.gz&response-content-type=application%2Foctet-stream

    anmo_mybatis_generator.zip

    response.setHeader("Content-Disposition", "attachment; filename=\"anmo.zip\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=...

Global site tag (gtag.js) - Google Analytics