Content-disposition中Attachment和inline和宏的区别的区别

java 文档下载response的设置 - 小宝 - ITeye技术网站
博客分类:
用java下载文档的时候设置response的几种方式
//response信息的设置
response.reset();
response.setContentType("application/pdf");
//导出PDF名称
String fileName = "客户数据分析结果报表";
//inline为在线打开
response.setHeader("Content-Disposition", " filename=\""
+ new String(fileName.getBytes("gb18030"), "ISO8859-1") + ".pdf" + "\"");
response.setContentLength(ba.size());
点击会提供对话框选择另存为:
response.setHeader("Content-Disposition", " filename=\"+filename);
通过IE浏览器直接选择相关应用程序插件打开:
response.setHeader("Content-Disposition", " filename=\"+filename);
下载前询问(是打开文件还是保存到计算机)
response.setHeader("Content-Disposition", " filename=\"+filename);
小宝制造。
浏览: 51171 次
来自: 沈阳
&pre name=&code& c ...
请教一个问题,我的页眉是用图片构成的,一个pdf大概20页左右 ...
一楼的做法也可以,业务一般是这样的点翻页的时候把查询条件带到翻 ...
我是这样解决的buildBbar : function() { ...
&div class=&quote_title ...您还未登陆,请登录后操作!
java中轉excel?r候attachment和inline的?^?e是什么﹖
ontent-disposition&,& filename=ORDER_OUT.xls&);
%&中的inline和attachment有什麼?^?e?
IntheextendedBNFnotationof[RFC822],theContent-Dispositionheaderfieldisdefined :="Content-Disposition"":"disposition-type*(";"disposition-parm)disposition-type:="inline"/"attachment"/extension-valuesarenotcase-sensitivedisposition-parm:=filename-parm/parameterfilename-parm:="filename""="`Extension-token',`parameter'and`value'aredefinedaccordingto[RFC822]and[RFC1521].Troost&DornerExperimental[Page2]RFC1806Content-DispositionJune19952.1TheInlineDispositionTypeAbodypartshouldbemarked`inl
IntheextendedBNFnotationof[RFC822],theContent-Dispositionheaderfieldisdefined :="Content-Disposition"":"disposition-type*(";"disposition-parm)disposition-type:="inline"/"attachment"/extension-valuesarenotcase-sensitivedisposition-parm:=filename-parm/parameterfilename-parm:="filename""="`Extension-token',`parameter'and`value'aredefinedaccordingto[RFC822]and[RFC1521].Troost&DornerExperimental[Page2]RFC1806Content-DispositionJune19952.1TheInlineDispositionTypeAbodypartshouldbemarked`inline'ifitisintendedtobedisplayedautomaticallyupondisplayofthemessage.Inlinebodypartsshouldbepresentedintheorderinwhichtheyoccur,subjecttothenormalsemanticsofmultipartmessages.2.2TheAttachmentDispositionTypeBodypartscanbedesignated`attachment'toindicatethattheyareseparatefromthemainbodyofthemailmessage,andthattheirdisplayshouldnotbeautomatic,butcontingentuponsomefurtheractionoftheuser.TheMUAmightinsteadpresenttheuserofabitmapterminalwithaniconicrepresentationoftheattachments,or,oncharacterterminals,withalistofattachmentsfromwhichtheusercouldselectforviewingorstorage.2.3TheFilenameParameterThesendermaywanttosuggestafilenametobeusediftheentityisdetachedandstoredinaseparatefile.IfthereceivingMUAwritestheentitytoafile,thesuggestedfilenameshouldbeusedasabasisfortheactualfilename,wherepossible.----------------------------see
大家还关注1332人阅读
多用途互联网邮件扩展(MIME,Multipurpose Internet Mail Extensions
,它扩展了
标准,使其能够支持非
格式附件等多种格式的邮件消息。这个标准被定义在
转变而来的
标准并不允许在邮件消息中使用7位ASCII字符集以外的字符。正因如此,一些非英语字符消息和二进制文件,图像,声音等非文字消息都不能在电子邮件中传输。MIME规定了用于表示各种各样的数据类型的符号化方法。 此外,在
中也使用了MIME的框架。
MIME是通过标准化电子邮件报文的头部的附加领域(fields)而实现的;这些头部的附加领域,描述新的报文类型的内容和组织形式。
内容类型(Content-Type),这个头部领域用于指定消息的类型。一般以下面的形式出现。
Content-Type: [type]/[subtype]; parameter
type有下面的形式。
Text:用于标准化地表示的文本信息,文本消息可以是多种字符集和或者多种格式的;
Multipart:用于连接消息体的多个部分构成一个消息,这些部分可以是不同类型的数据;
Application:用于传输应用程序数据或者二进制数据;
Message:用于包装一个E-mail消息;
Image:用于传输静态图片数据;
Audio:用于传输音频或者音声数据;
Video:用于传输动态影像数据,可以是与音频编辑在一起的视频数据格式。
subtype用于指定type的详细形式。content-type/subtype配对的集合和与此相关的参数,将随着时间而增长。为了确保这
些值在一个有序而且公开的状态下开发,MIME使用Internet Assigned Numbers Authority
(IANA)作为中心的注册机制来管理这些值。常用的subtype值如下所示:
text/plain(
text/html(HTML文档)
application/xhtml+xml(XHTML文档)
image/gif(GIF图像)
image/jpeg(JPEG图像)【PHP中为:image/pjpeg】
image/png(PNG图像)【PHP中为:image/x-png】
video/mpeg(MPEG动画)
application/octet-stream(任意的二进制数据)
application/pdf(PDF文档)
application/msword(Microsoft Word文件)
message/rfc822(
multipart/alternative(HTML邮件的HTML形式和纯文本形式,相同内容使用不同形式表示)
application/x-www-form-urlencoded(使用HTTP的POST方法提交的表单)
multipart/form-data(同上,但主要用于表单提交时伴随文件上传的场合)
此外,尚未被接受为正式数据类型的subtype,可以使用x-开始的独立名称(例如application/x-gzip)。vnd-开始的固有名称也可以使用(例:application/vnd.ms-excel)。
parameter可以用来指定附加的信息,更多情况下是用于指定text/plain和text/htm等的文字编码方式的charset参数。
MIME根据type制定了默认的subtype,当客户端不能确定消息的subtype的情况下,消息被看作默认的subtype进行处理。Text默
认是text/plain,Application默认是application/octet-stream而Multipart默认情况下被看作
multipart/mixed。
以上出现的&消息&翻译自message
如:HTTP/1.1中
&&&&&& Response&&&&& = Status-Line
&&&&&&&&&&&&&&&&&&&&&& *(( general-header
&&&&&&&&&&&&&&&&&&&&&&& | response-header
&&&&&&&&&&&&&&&&&&&&&&& | entity-header ) CRLF)
&&&&&&&&&&&&&&&&&&&&&& CRLF
&&&&&&&&&&&&&&&&&&&&&& [ message-body ]
Content-Disposition
在进行Web开发时,可能遇到遇到以下几种需求:
l&&&&&&&&& 希望某类或者某已知MIME 类型的文件(比如:*.*.*.htm)能够在访问时弹出&文件下载&对话框。
l&&&&&&&&& 希望客户端下载时以指定文件名显示。
l&&&&&&&&& 希望某文件直接在浏览器上显示而不是弹出文件下载对话框。
对于上面的需求,使用Content-Disposition属性就可以解决。下面是代码示例:
response.setHeader(&Content-disposition&, &filename=& + fileName)。
//Content-disposition为属性名。
//attachment表示以附件方式下载。如果要在页面中打开,则改为inline。
//filename如果为中文,则会出现乱码。解决办法有两种:
//1、使用fileName = new String(fileName.getBytes(), &ISO8859-1&)语句
//2、使用fileName = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)语句
参考文档:
HTTP/1.1 附录:
维基百科:
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:64989次
积分:1114
积分:1114
排名:千里之外
原创:36篇
转载:51篇
(2)(10)(2)(1)(2)(5)(2)(1)(6)(14)(4)(10)(2)(1)(27)HTTP 报头,Content-disposition_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
文档贡献者
评价文档:
HTTP 报头,Content-disposition
缓​存​知​识
大小:4.69KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢下次自动登录
现在的位置:
& 综合 & 正文
content-disposition attachment filename 在Firefox和IE中得到不同的结果
在Firefox中需要把filename 用双引号包起来,才能得到想要的名字,不然如果含有空格,会丢掉空格后面的部分。而IE会把空格转为_,因此也需要HttpUtility.UrlPathEncode方法处理下名字。如果Firefox中也用HttpUtility.UrlPathEncode处理名字,空格将被替换成"%20".
HttpContext.Current.Response.Buffer = true; 2
HttpContext.Current.Response.ClearContent(); 3
HttpContext.Current.Response.ClearHeaders(); 4
HttpContext.Current.Response.ContentType = "Application/pdf"; 5
string doc1 = System.IO.Path.GetFileNameWithoutExtension(doc) + "_" + intNewID.ToString() + ".pdf"; 6
if(HttpContext.Current.Request.Browser.Browser != "IE") 8
HttpContext.Current.Response.AddHeader("Content-Disposition", "filename=\"" +doc1+"\""); 9
HttpContext.Current.Response.AddHeader("Content-Disposition", "filename="+ HttpUtility.UrlPathEncode( doc1));11
byte[] buffer=System.IO.File.ReadAllBytes(doc);12
HttpContext.Current.Response.AddHeader("Content-Length", buffer.Length.ToString());13
HttpContext.Current.Response.BinaryWrite(buffer);
Firefox does not handle filenames with spaces . When a user clicks on an attachment with spaces, the filename is truncated to the first whitespace. While IE & Safari both handle this, Firefox refuses to accept mime headers with unquoted filename parameters. According to Firefox's bugzilla/knowledgebase, Firefox's behavior is the correct behavior and it's a problem with most webservers or web applications. This problem can be easily corrected by surrounding the filename parameter with double quotes.
&&&&推荐文章:
【上篇】【下篇】

我要回帖

更多关于 inline block 区别 的文章

 

随机推荐