struts DownloadAction 下载问题

yyy851124 2009-03-04 10:30:00
protected StreamInfo getStreamInfo(ActionMapping arg0, ActionForm arg1,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String contentType="application/msword";
//String filed= request.getParameter("filed");
//String filename = request.getParameter("fileName");
//String iso_filed=new String(filed.getBytes("iso-8859-1"),"gbk");
//工程内的文件就可以
//String root=servlet.getServletContext().getRealPath("/");
//String filePath = root+"\\"+filed+"\\"+filename;

//指定的文件总是下载不了
File file = new File("E:\\file\\yeyang\\dwr.rar");
System.out.println(file.getAbsolutePath());

response.setContentType("application/x-msdownload;charset=gbk");
response.setHeader("Content-Disposition","attachment; filename="
+new String("dwr.rar".getBytes("gbk"),"iso-8859-1"));
return new FileStreamInfo(contentType, file);
}
...全文
115 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ncowboy 2009-03-06
  • 打赏
  • 举报
回复
获取到HttpServletResponse对象,然后:



response.setContentType("message/rfc822");
response.setHeader("Content-Disposition",
"attachment; filename=" + mailLocalID + ".eml");
response.getOutputStream().write(mb.getContent());

81,122

社区成员

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

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