http之Content-Disposition 属性

Content-Disposition 属性是作为对下载文件的一个标识字段,Content-Disposition属性有两种类型:inline 和 attachment 。

inline :将文件内容直接显示在页面;attachment:弹出对话框让用户下载。下面上代码:

1.在页面内打开代码:

response.setHeader("Content-Type","text/plain");

response.addHeader("Content-Disposition","inline;filename="+new String(filename.getBytes(),"utf-8"));

response.addHeader("Content-Length",""+file.length());

2.弹出保存框代码:

response.setHeader("Content-Type","text/plain");

response.addHeader("Content-Disposition","attachment;filename="+new String(filename.getBytes(),"utf-8"));

response.addHeader("Content-Length",""+file.length());

猜你喜欢

转载自blog.csdn.net/ahutdbx/article/details/82745498
今日推荐