有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

下载后java CSV文件被截断

遗留J2EE应用程序详细信息:

  • JSP+servlet(2.4)
  • Websphere Application Server 7.0
  • 该视图使用IE框架、核心javascript等

用户的操作:

  • 用户搜索返回>;显示900行需要一些时间(无分页)
  • 用户然后点击“下载”按钮,再次触发表单提交

以下是在action servlet中执行的代码片段:

public class DownloadFileEvent extends ActionGeneric {

    java.text.SimpleDateFormat df_file = new java.text.SimpleDateFormat("yyyyMMdd_HHmmss");

    public void run(HttpServletRequest request, HttpServletResponse response) throws Exception {

        String errormsg = null;
        StringBuffer LineBuffer = null;

        // read parameters.
        String _v = request.getParameter("view");

        // Start traitment.
        try {
            // get sessions.
            ServletOutputStream out = response.getOutputStream();

            // Create title columns.
            response.setContentType("application/csv");
            response.setHeader("Content-Disposition", "inline; filename = " + getFilename(_v));
            LineBuffer = new StringBuffer();

            //Get the string response from some business method
            //String v_wrk = getOutflow(request, _v).toString();

            LineBuffer.append(v_wrk);
            LineBuffer.append("\r\n");
            out.print(LineBuffer.toString());
            out.flush();
            // end.

        }// fin try
        catch (Exception e) {
            errormsg = e.getMessage();
        } finally {
            // to do.
        }
    }// end run.

}// fin class

问题

  • 由于“下载”需要一些时间,用户会转到其他屏幕

  • 当他回来时,“打开/保存/另存为”提示已经存在了一段时间。现在,当用户保存/打开文件时,不是900行,而是少于100行

  • 令人惊讶的是,如果立即打开/保存,所有行都会被下载

  • 在catch块中,我放了一个日志,但任何地方都没有例外

  • 这个问题不是在我的本地机器(Windows,WAS 7)或系统测试环境(Linux,WAS 8.5)中模拟的,而是在验收(WAS 7,Linux)和生产(WAS 7,Linux)时出现的。验收和生产部门安装了负载平衡器和web服务器,但未在systest或本地安装

我该怎么做


共 (1) 个答案

  1. # 1 楼答案

    在web服务器中尝试使用较大的SendBufferSize。如果在对话框打开时客户端没有读取,这将防止Web服务器看到写入操作最终阻塞然后超时