我用 public InputStream getDownloadFile()
    { 
      //  获得 ServletContext 对象
        ServletContext  servletContext =  
             ServletActionContext.getServletContext(); //  返回被下载文件的 InputStream 对象
        return servletContext.getResourceAsStream(inputPath);
    } 
获取到了一个输入流对象,怎么只是下载到浏览器上?
<action name="download" class="org.usc.file.DownloadAction">
<result name="success" type="stream">
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
struts已经配置过了

解决方案 »

  1.   

    如果不能调用下载器的话,如何在服务器的action代码中实现远程下载
      

  2.   

    j2ee,ssh,oracle...二十余个java内部项目视频,少年,要相信项目改变命运,Q1583539597  
      

  3.   

    下载文件哪里是这样的你要通过往这个下载文件请求的Response里面写二进制数据,将数据传送到客户端
      

  4.   

    下载文件就一个response就可以了,不需要整的的这么复杂呢,看代码:/**
     * 下载文件
     * @param filePath 文件路径(物理路径)
     * @param fileName 源文件名称
     */
    public void downLoadFile(String filePath, String fileName) {
    File file = new File(filePath);
    if (!file.exists() || file.isDirectory()) {
    return;
    }
    InputStream input =null;
    OutputStream output = null;
    try {
    input = new FileInputStream(file);
    output = getResponse().getOutputStream();
    getResponse().setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
    byte[] buffer = new byte[1024];
    int i = 0;
    while ((i = input.read(buffer)) != -1) {
    output.write(buffer, 0, i);
    }
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    try {
    if(null !=output) {
    output.flush();
    output.close();
    }
    if(null !=input) {
    input.close();
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    我把段代码封装在父类action中,需要做下载时,直接调用一下就OK了!