惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 数码民工

Jabber 技 术 概 况 [收藏] 2005年的第一场暴力--《最恶都市》 appfuse中集成valuelist 揭开极端编程的神秘面纱: 测试驱动的编程 揭开极端编程的神秘面纱: 工作的首选(XP)工具 hibernate3的中文查询问题 [转]AppFuse中使用Oracle需要注意的问题 IntelliJ IDEA最佳中文字型設定 Sunjava虚拟机和Bea JRockit虚拟机垃圾收集器--gc的机制详解 使用Ant管理配置Weblogic WebLogic Server 8.1虚拟主机配置最佳实践 WebLogic管理指南[转] WebLogic Server 管理最佳实践 通用OLAP方案 什么是联机分析处理(OLAP) 绝望-《帝国的毁灭》 悲怆:IT人的一声叹息-一个程序员的自白 新的开始 反派大聚会-《半条命2》中的联合军
[转]AppFuse中的SiteMesh问题
数码民工 · 2005-06-05 · via 博客园 - 数码民工

http://www.blogbus.com/public/tb.php/1216085
 因为AppFuse中使用的默认的JSP模板为SiteMesh,默认情况下,所有的请求都会被SiteMesh所装饰,所以我要实现点击文件链接,直接下载文件时却得不到正确格式的文件,得到的是一个html文件,即使制定了下载文件的类型:如:application/msexcel或者其他的类型都不行,我分析是因为,我首先向输出流中写了些东西,后来被SiteMesh使用getWriter方法给冲掉了,所以得到的是默认的网页文件,我折腾了2天,痛不欲生,刚刚解决掉这个问题,解决方法如下:

1.将下载文件的jsp放到一个特殊的目录下,我的放在download目录,这样可以区分需要被sitemesh装饰和不需要被它装饰的文件。

2.配置sitemesh的decorators.xml:
<decorators defaultdir="/decorators">
    <excludes>
        <pattern>/download/*</pattern>
    </excludes>
</decorators>

这个配置指明download下的文件不需要被sitemesh装饰。

我的下载文件的页面代码是试验代码,稍加修改就可以正式使用,代码如下:
<%@ page import= "java.io.*,java.net.*" %><%
    try{
        //取得虚拟的路径
        String fn = "attachment; filename=a.xls";  //必须改为UniCode编码的字符串
        System.out.println(fn);
        //把标题、内容写到输出流中
        response.setHeader("Content-Disposition", new String(fn.getBytes("GB2312"),
                                        "ISO-8859-1"));
        createOutput( response.getOutputStream(),"c:\\ltf.xls");
    }catch( Exception ee ){
        ee.printStackTrace();
    }
%><%!
public void createOutput( OutputStream out,String realpath ) throws IOException {
    int b;
    BufferedInputStream  m_input =
                new BufferedInputStream( new  FileInputStream(realpath) );
    while( (b = m_input.read()) != -1 ){
        out.write(b);
    }
    m_input.close();
    out.flush();
    out.close();
}
%>
<%--
  // 得到文件名字和路径
  String filename = request.getParameter("zipfilename");
  //String jsppath = "";             getServletConfig().getServletContext().getRealPath("") +
   String filepath = "c:\\ltf.xls";        //jsppath.substring(0,jsppath.lastIndexOf("")) + "reports\\";
  System.out.println("---------------=================" + filepath);
  java.io.FileInputStream fileInputStream = null;
  //out.println(filepath);
  // 设置响应头和下载保存的文件名
  response.setHeader("Content-Disposition",
  "attachment; filename=" + "a.xls");
  response.setContentType("application/msexcel");
 
  // 打开指定文件的流信息
  try{
  fileInputStream =
   new java.io.FileInputStream(filepath);
  
  // 写出流信息
  int i;
  while ((i=fileInputStream.read()) != -1) {
   out.write(i);
  }
  fileInputStream.close();
  out.close();
  System.out.println("---OK---------------");
  
  }catch(Exception ee){
    ee.printStackTrace();
  }
--%>