JSP强制下载一个文件?

hero 2001-05-08 01:51:00
代码如下:

response.setContentType("application/download");
DataOutputStream os = new DataOutputStream(response.getOutputStream() );
response.setContentLength(4);
os.writeUTF("test") ;
os.close();

只显示内容,不下载,怎么办?


...全文
145 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hero 2001-05-10
  • 打赏
  • 举报
回复
我的意思是既不显示,也不下载。
skyyoung 2001-05-09
  • 打赏
  • 举报
回复
那行吗?
hero 2001-05-09
  • 打赏
  • 举报
回复
这回不显示了。
skyyoung 2001-05-09
  • 打赏
  • 举报
回复
response.setContentType("application/x-unknown-text-html");
DataOutputStream os = new DataOutputStream(response.getOutputStream());
response.setContentLength(4);
os.writeUTF("test") ;
os.close();

// 行吗
hero 2001-05-09
  • 打赏
  • 举报
回复
能在 servlet的 doGet()中完整的写个例子吗?
拜托帮帮忙,我都快急死了!分数我有的是。

skyyoung 2001-05-09
  • 打赏
  • 举报
回复
可以
xxx = "text/html"; // 或其它
response.setContentType("application/x-unknown-"+ xxx);
qinjia 2001-05-08
  • 打赏
  • 举报
回复
jsp中就是不行,因为jserver和apache已经将*.jsp归为 text/plain 或者 text/html 了,所以你怎么搞也不行了。只有更改 httpd.conf 才可以。
或者使用 servlet
skyyoung 2001-05-08
  • 打赏
  • 举报
回复
我这里都行哦。
flywow 2001-05-08
  • 打赏
  • 举报
回复
全错"application/x-msdownload“类型才对。请加分
hero 2001-05-08
  • 打赏
  • 举报
回复
楼上老兄,还是只显示文件内容,不下载。
真的,我不骗你的。
skyyoung 2001-05-08
  • 打赏
  • 举报
回复
try
response.setContentType("application/x-filler");
skyyoung 2001-05-08
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/83/83102.shtm

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧