lagbr 2015-07-22 08:46 采纳率: 0%
浏览 1381

新手求教!!关于使用struts 下载csv文件的问题 急

我配置好struts后,点击下载的时候页面没有任何的响应,这是为什么啊?
struts.xml

  <action name="xxDownload" class="com.xx.action.xxAction"
            method="download" >
            <result name="success" type="stream">  
                <param name="contentType" >application/csv</param > 
                <param name="inputName" >stream</param> 
                <param name="contentDisposition" >
                    attachment;filename="${fileName}"
                </param>  
                <param name="bufferSize" >4096</param> 
            </result>

xxAction

 private InputStream stream;
String fileName;

public String download(){
    try {
        xx= service.search(condition);
        fileName = "xx_"+Math.random()+".csv";
        File file = new File(fileName);
        OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        String str = ".........shenglve\n";
        out.write(str.getBytes());
        out.flush();
        for (int i = 0; i < x.size(); i++) {
            str = xx.get(i).getStoreCD() + ","
                + xx.get(i).getProductCD() + ","
                + xx.get(i).getStartDate() + ","
                + xx.get(i).getEndDate() + ","
                + xx.get(i).getMassExposure() + ",aa\n";
            out.write(str.getBytes());
            out.flush();
        }
        out.flush();
        stream = new FileInputStream(file);  
    } catch (Exception e) {
        logger.error(e.getMessage(),e);
        exFlag = "1";
    }
    return "success";
}

js

 var msg ="是否下载?";
        if(window.confirm(msg)){
            var url = "xxDownload";
            var param = {
                "xx.a":"1"
                ,"xx.b":"2"
                ,"xx.c":"3"
                ,"xx.d":""
            };
            $.post(url,param);
        }
  • 写回答

2条回答 默认 最新

  • threenewbee 2015-07-22 11:02
    关注

    post不会引起跳转,也不会触发下载,需要用window.location=xxx跳转引发下载。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog