`
stenlylee
  • 浏览: 255424 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Seam下载文件的问题

阅读更多

Seam默认下载文件会变成直接在网页中打开内容,主要是因为Response header的问题,需要手工调节下,大概思路如下:

 

public String download() {   
        Attachment attachment = entityManager.find(Attachment.class, attachmentId);   
        HttpServletResponse response = (HttpServletResponse)extCtx.getResponse();   
        response.setContentType(attachment.getContentType());   
                response.addHeader("Content-disposition", "attachment; filename=\"" + attachment.getName() +"\"");   
        try {   
            ServletOutputStream os = response.getOutputStream();   
            os.write(attachment.getData());   
            os.flush();   
            os.close();   
            facesContext.responseComplete();   
        } catch(Exception e) {   
            log.error("\nFailure : " + e.toString() + "\n");   
        }   
  
        return null;   
    }  

 不过这样似乎也有问题,要把文件全部读入内存然后在下载……

 

不知道有人知道其他办法没,有待补充

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics