李树超 2013-05-31 12:18 采纳率: 100%
浏览 147
已采纳

struts2 文件下载 cpu 占用 100%,求解决方案

xml

 

   <action name="L_download" class="cnydlanFileAction" method="download">
            <result name="success" type="stream">
                <param name="contentType">application/octet-stream;charset=ISO8859-1</param>
                <param name="inputName">inputStream</param>
                <param name="contentDisposition">attachment;filename="${downloadFileName}"</param>
                <param name="bufferSize">4096</param>
            </result>
        </action>

action

 

  /**
     * 处理中文下载名
     * @throws Exception 
     * 
     */
    public String getDownloadFileName() throws Exception {
        String named = new String(name.getBytes(), "ISO8859-1");
        if (zipName1.length() > 0){
            named = new String(zipName1.getBytes(), "ISO8859-1");
        }
        return named;
    }

    /**
     * 获得文件下载流
     */
    public InputStream getInputStream() throws Exception { 
        HttpServletRequest actionRequest = ServletActionContext.getRequest();
        Map session = (Map)ActionContext.getContext().getSession();
        String[] tt = getPaths();
        if (tt != null && tt.length > 0){
            this.paths = URLDecoder.decode(tt[0], "UTF-8").split(",");
            compressionFilesToTemparayPackage();
            String path1 = "";
            path1 = getTempPath() + zipName1;
            deleteZipFiles();
            InputStream in = new FileInputStream(path1); 
            return in;
        } else {
            logger.info("IP: " + actionRequest.getRemoteAddr() + " 开始下载文件" + name + " time: " + getTime());
            String path1 = "";
            String temproot = path;
            String para1 = getRoot();
            if (temproot.equals("*") == false){
                path1 = getRoot() + temproot + "\\" + name;
                para1 = getRoot() + temproot;
            } else { path1 = getRoot() + "\\" + name;}
            para1 = path1; //getFullPathSetDataBase(para1, name);
            markDownLoadInfo(para1, name);
            InputStream in = new FileInputStream(path1); 
            logger.info("IP: " + actionRequest.getRemoteAddr() + " 结束下载文件" + MyUtils.URLDecoder(name) + " time: " + getTime());
            return in;
        }
    }

    /**
     * 下载文件
     */
    public String download() {
        return SUCCESS;
    }

 

 

  • 写回答

1条回答 默认 最新

  • M44346460 2013-05-31 18:14
    关注

    struts2的download是不会造成CPU负载过高的,你的代码中,有好几个方法:分别是压缩存放到临时文件夹(compressionFilesToTemparayPackage)、删除压缩后的文件(deleteZipFiles)、标记下载信息(markDownLoadInfo)。我建议你可以把这三个方法先去掉,然后逐个方法加入调试。这是个小问题,试试吧!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒