0

Struts2 アプリケーションからファイルをダウンロードすると、ファイルのダウンロード後にセッションが期限切れになります。これは起こらないはずです。

setMaxInactiveInterval() を使用してセッション タイムアウトを設定できますが、ファイル サイズは一定ではなく、ダウンロード時間はファイル サイズなどによって異なります。

解決策を教えてください。

私のファイルダウンロードコードは次のとおりです。

InputStream fileInputStream = null;
    File file = null;
    String fileDir = "C:\\CAP\\FileDownload\\file\\";
    String fileName = "SW.zip";
    HttpSession sessio = null;

    try {
        sessio = request.getSession();
        logger.debug("--------------->>>>"+sessio.getMaxInactiveInterval());
        file = new File(fileDir+fileName);
        logger.debug(":::::::::-->"+file.isFile());
        fileInputStream = new FileInputStream(file);

        ServletOutputStream outputStream = null;
        response.addHeader("Content-Disposition", "attachment; filename="
          + fileName);
        response.setContentLength((int) file.length());
        outputStream = response.getOutputStream();

        // Copy the contents of the file to the output stream
        byte[] buf = new byte[1024];
        int count = 0;
        while ((count = fileInputStream.read(buf)) >= 0) {
            outputStream.write(buf, 0, count);
            logger.debug("Count Is : "+count);
        }

        logger.debug("====================compleated the file donlowding ====================");
    } catch (IOException e) {
        logger.error("ERROR while reading and wring file : "
                + e.getMessage());

    }
4

2 に答える 2

0

ファイル サイズが十分に大きく、時間がセッション タイムアウトを超える場合は、ファイルを並べてダウンロードする ASynchronise サービスを使用して、ユーザーが作業を続行できるようにすることをお勧めします。バッチのようなもの。

于 2013-02-21T08:24:15.257 に答える
0

request.getSession(false)as を使用してrequest.getSession()、このリクエストに関連付けられた現在のセッションを返します。リクエストにセッションがない場合は作成します。

したがって、あなたの場合、ダウンロードが完了するとすぐに破棄されるrequest.getSession()新しいものを作成していると思います。session

于 2013-02-21T08:20:18.087 に答える