怎么搞的啊,好不容易研究STRUTS2下载,成功是成功了,可是不弹出下载框。我晕啊 。
public class MailDownloadAction extends ActionSupport {

private long id;
private MailDAO mdao;
private String downFile;
public String getDownFile() {
return downFile;
}
public void setId(long id) {
this.id = id;
}
public void setMdao(MailDAO mdao) {
this.mdao = mdao;
}

// 下载 获取输入流
   public InputStream getDownloadFile() {       System.out.println("/uploads"+"/"+this.getDownFile());
return ServletActionContext.getServletContext().getResourceAsStream(
"/uploads"+"/"+this.getDownFile());
}

@Override
public String execute() throws Exception {
this.downFile=this.mdao.getMailById(this.id).getFilepath();
return SUCCESS;
}


}
<!-- 下载 -->
<action name="mailDownload*" class="mailDownloadAction" >
<param name="id">{1}</param>
<result name="success" type="stream">
<param name="contentType">application/zip,application/xml,application/vnd.ms-excel,video/x-ms-wmv,audio/x-wav,text/plain,
application/x-shockwave-flash,application/vnd.ms-powerpoint,application/pdf,video/mpeg,video/mp4,audio/mpeg,image/jpeg,
text/plain,application/java-archive,image/x-icon,text/html,image/gif,application/msword,image/bmp
</param>
<param name="contentDisposition">filename="${downFile}"</param>
<param name="inputName">downloadFile</param>
</result>
</action>

解决方案 »

  1.   

    我写过的这种,是弹出提示框的,仅供参考!
    // 以流的形式下载文件。
    InputStream fis = new BufferedInputStream(new FileInputStream(file));
    byte[] buffer = new byte[fis.available()];
    fis.read(buffer);
    fis.close(); // 清空response
    resp.reset(); // 设置response的Header
    resp.setCharacterEncoding("UTF-8");
    resp.addHeader("Content-Disposition", "attachment;filename=" +   URLEncoder.encode(filename ,"UTF-8"));
    resp.addHeader("Content-Length", "" + file.length());
    OutputStream toClient = new BufferedOutputStream(resp.getOutputStream());
    resp.setContentType("application/octet-stream");
    toClient.write(buffer);
    toClient.flush();
    toClient.close();