web.xml 中的会话超时 [英] Session TimeOut in web.xml

查看:22
本文介绍了web.xml 中的会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 Web.xml 中会话超时配置的真正目的.

I am trying to understand the real purpose of session configuration in Web.xml for session timeout.

<!-- Session Configuration -->
<session-config>
        <session-timeout>60</session-timeout>
</session-config>

现在让我告诉你我的问题.

Now let me tell you about my question.

我的应用程序正在导入/上传一个 .txt 文件,这肯定需要 1 个多小时,因为要导入数百万条记录.但是会话在 1 小时后超时,尽管我的应用程序仍在导入正在进行的 .txt 文件.此类应用程序不应超时,因为该应用程序正在后台执行某些任务.

My application is importing/uploading a .txt file, which is bound to take more than 1 hour, since there are millions of records to be imported. But the session times out after 1 hour though my application is still importing that .txt file which is in progress. Such an application should not timeout as the application is doing some task in the background.

推荐答案

设置永不过期的会话超时是不可取的,因为您可以可靠地让用户在每次完成时按下注销按钮以防止您服务器负载过多(取决于用户数量和硬件).此外,您可能会遇到一些您宁愿避免的安全问题.

To set a session-timeout that never expires is not desirable because you would be reliable on the user to push the logout-button every time he's finished to prevent your server of too much load (depending on the amount of users and the hardware). Additionaly there are some security issues you might run into you would rather avoid.

在服务器仍在处理任务时会话失效的原因是因为客户端(用户浏览器)和服务器端之间没有通过例如一个 http 请求.因此服务器无法知道用户状态,认为他正在空闲并在您的 web.xml 中设置的时间之后使会话无效.

The reason why the session gets invalidated while the server is still working on a task is because there is no communication between client-side (users browser) and server-side through e.g. a http-request. Therefore the server can't know about the users state, thinks he's idling and invalidates the session after the time set in your web.xml.

要解决这个问题,您有几种可能性:

To get around this you have several possibilities:

  • 您可以在任务运行时ping您的后端以访问会话并防止其过期
  • 增加服务器内的,但我不建议这样做
  • 在专用线程中运行您的任务,该线程在工作时接触(扩展)会话或在线程完成时通知用户
  • You could ping your backend while the task is running to touch the session and prevent it from being expired
  • increase the <session-timeout> inside the server but I wouldn't recommend this
  • run your task in a dedicated thread which touches (extends) the session while working or notifies the user when the thread has finished

有人问过类似的问题,也许您可​​以在您的项目中调整此解决方案的部分内容.看看这个.

There was a similar question asked, maybe you can adapt parts of this solution in your project. Have a look at this.

希望这会有所帮助,玩得开心!

Hope this helps, have Fun!

这篇关于web.xml 中的会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆