• 在下载txt文件的时候不在IE里面直接打开,而是下载


    方法一:
    SmartUpload su = new SmartUpload();
     // 初始化 su.initialize(pageContext);
     // 设定contentDisposition为null以禁止浏览器自动打开文件,
    //保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
    //doc时,浏览器将自动用word打开它。扩展名为pdf时,
    //浏览器将用acrobat打开。
    su.setContentDisposition(null);
    =============================
     
    方法二:
    <%
    // example:
    // <a href="download.jsp?path=img/&name=test.gif">download image</a>
    String root = getServletContext().getRealPath("/");
    String path = request.getParameter("path");
    String name = request.getParameter("name");
    response.setContentType("unknown");
    response.addHeader("Content-Disposition", "filename=\"" + name + "\"");
    try
    {
    java.io.OutputStream os = response.getOutputStream();
    java.io.FileInputStream fis = new java.io.FileInputStream(root + path + name);
    byte[] b = new byte[1024];
    int i = 0;
    while ( (i = fis.read(b)) > 0 )
    {
    os.write(b, 0, i);
    }
    fis.close();
    os.flush();
    os.close();
    }
    catch ( Exception e )
    {
    }
    %>
    ==============================
     
    方法三:
    <script>
    var n=0;
    function go(url){
       
        n==0?new function()
        {
            frames("frame1").location=url,n=1
        }:null;
       
        document.all("frame1").readyState!="complete"?setTimeout(go,10):so();
       
        function so()
        {
            frames("frame1").document.execCommand("SaveAs"),n=0
        };
    }
    </script>
    <iframe id="frame1" style="display:none"></iframe>
    <a  onClick="go('java.txt')" class="style2">下载</a>
  • 相关阅读:
    垃圾收集器
    垃圾收集算法
    动态绑定
    数据库连接池原理
    分布式事务:两段式提交(最终一致性)
    C# 推箱子游戏&对战游戏
    C# 结构体和类的区别
    C# 类&结构体&枚举
    C# 哈希表&列队&栈
    C# 数组&集合&泛型集合
  • 原文地址:https://www.cnblogs.com/hyd309/p/1986291.html
Copyright © 2020-2023  润新知