电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> jsp>>用JSP编程实现word文件下载(点击下载-非ie打开):

用JSP编程实现word文件下载(点击下载-非ie打开)

来源:网络 | 2008-8-5 | (有6216人读过)

<%@page import="java.util.*"%> 
<%@page import="java.io.*"%> 
<%@page import="java.net.*"%> 
<% 
    String filename = ""; 
    if (request.getParameter("file") != null) { 
        filename =     request.getParameter("file"); 
    } 
    response.setContentType("application/msword"); 
    response.setHeader("Content-disposition","attachment; filename="+filename); 
     
    BufferedInputStream bis = null; 
    BufferedOutputStream bos = null; 
    try { 
        bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename))); 
        bos = new BufferedOutputStream(response.getOutputStream()); 

        byte; 
        int bytesRead; 

        while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) { 
            bos.write(buff,0,bytesRead); 
        } 

    } catch(final IOException e) { 
        System.out.println ( "出现IOException." + e ); 
    } finally { 
        if (bis != null) 
            bis.close(); 
        if (bos != null) 
            bos.close(); 
    } 
    return; 
%> 
jsp热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号