采用RequestDispatcher的方式进行          jsp页面中添加如下代码:
         <%
    response.setContentType("application/x-download");//设置为下载application/x-download
    String filedownload = "//要下载的文件名";//即将下载的文件的相对路径
    String filedisplay = "最终要显示给用户的保存文件名";//下载文件时显示的文件保存名称
    filenamedisplay = URLEncoder.encode(filedisplay,"UTF-8");
    response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
    
    try
    {
        RequestDispatcher dis = application.getRequestDispatcher(filedownload);
        if(dis!= null)
        {
            dis.forward(request,response);
        }
        response.flushBuffer();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
    
    }
%>   这个代码执行后出现下载提示页面,但是文件的大小始终是2KB ,完全与实际的文件大小不符合,请问这个问题怎么解决
  这段下载代码我也是看得网上的,求求各位,真的很着急

解决方案 »

  1.   

    有这样的下载代码吗?我不懂哦,好像我的代码不是这样的(代码在公司)
      

  2.   

    有这样的下载代码吗?我不懂哦,好像我的代码不是这样的(代码在公司)
    ------------------------------------------------------------------
    这个代码我也是看得网上的, 能不能把你的代码贴上来给我看看
      

  3.   

    哪位能看看这个是怎么回事,小弟跪求答案......