Когда я загружаю файл из приложения 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());
}
Сколько времени занимает загрузка файла? – Apurv
Зачем вам нужен сеанс, чтобы продлиться все время загрузки? Загрузка должна быть запущена в другом окне браузера, тогда пользователи могут продолжать использовать приложение, верно? –