定义自定义事件/操作/请求以在 Java Web App 中为会话超时重置计时器? [英] Define custom events/actions/requests for resetting timer for Session Timeout in Java Web App?

查看:14
本文介绍了定义自定义事件/操作/请求以在 Java Web App 中为会话超时重置计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Eclipse 中为我的 Web 应用程序使用 Tomcat 7.0、Spring 4.0.2、Web Module 3.0.我在 app/web.xml 和 tomcat/conf/web.xml 中配置了我的会话超时.

I am using Tomcat 7.0, Spring 4.0.2, Web Module 3.0 in eclipse for my web application. And I configured my session timeout in app/web.xml as well as tomcat/conf/web.xml.

<session-config><session-timeout>30</session-timeout></session-config>

我知道 tomcat 必须重置它的内部计时器来计算这 30 分钟并使会话(会话超时)在某些事件/操作/请求上无效.

I know that tomcat must reset it's internal timer for calculate this 30 mins and invalidate session (session timeout) on some events/actions/requests.

我每 5 分钟发送一个名为 captureLastActiveTimeForCurrentFile 的请求.所以现在应用程序服务器永远不会使会话无效,因为我每 5 分钟发送一次请求,所以它会在每 5 分钟后重置它的会话超时计时器.

I am sending one request called captureLastActiveTimeForCurrentFile after every 5 mins. So now application server will never invalidate session because I am sending request after every 5 mins, so it will reset it's session timeout timer after every 5 mins.

现在我的问题是如何忽略重置会话超时计时器的任何特定请求(此处为captureLastActiveTimeForCurrentFile).这意味着当我发送 captureLastActiveTimeForCurrentFile 请求时,服务器不得重置它的计时器.对于所有其他请求,它应该可以正常工作.所以假设如果我不向服务器发送任何其他(不包括 captureLastActiveTimeForCurrentFile)请求,它必须在 30 分钟后使会话无效.

Now my problem is that how to ignore any particular request (here, captureLastActiveTimeForCurrentFile) for resetting session timeout timer. It means when I send captureLastActiveTimeForCurrentFile request, server must not reset it's timer. For All others requests it should work as it is how it is already working. So suppose if I do not send any other (excluding captureLastActiveTimeForCurrentFile) requests to server, it must be invalidate session after 30 mins.

我能想到的解决方案:
--> 我将在 web.xml 文件中配置会话超时很长时间.
--> 在服务器上每次请求调用后,我将在一个全局变量中捕获上次请求时间,不包括 captureLastActiveTimeForCurrentFile
--> 我将启动我自己的调度程序,它将在每 5 分钟后运行一次,它会检查上次请求时间 - 当前时间 > 30 分钟,然后我将手动使会话无效.

The solution I can think :
--> I will configure session timeout very long time in web.xml file.
--> I will capture last request time in one Global variable after every request call on server excluding captureLastActiveTimeForCurrentFile
--> I will start my own scheduler which will run after every 5 min and It will check last request time - current time > 30 mins, then I will invalidate session manually.

但我认为这个解决方案很复杂,而且在性能方面不是一个好主意.

But I think this solution is complicated and performance wise not a good idea.

有没有其他方法可以在服务器上配置排除的请求,以便服务器忽略该特定请求.

Is there any other way by which I can configure excluded requests on server, so that Server will ignore that particular request.

如果我的任何假设有误,请纠正我.提前致谢.任何帮助将不胜感激.

Correct me if any of my assumptions are wrong. Thanks in advance. Any help would be appreciate.

推荐答案

如果 captureLastActiveTimeForCurrentFile 背后的代码没有显式访问用户的 HTTP 会话(即通过调用 request.getSession()),那么您可以忽略对该路径的请求在 Tomcat 中设置一些属性.请注意,设置这些会为未显式访问用户会话的任何其他映射引入类似的行为.

If the code behind captureLastActiveTimeForCurrentFile does not explicitly access the user's HTTP Session (i.e. by calling request.getSession()) then you can ignore the request to this path by setting some properties in Tomcat. Note that setting these however will introduce similar behavior for any other mappings not explicitly accessing the user's session.

相关属性为:

org.apache.catalina.core.StandardHostValve.ACCESS_SESSIONorg.apache.catalina.STRICT_SERVLET_COMPLIANCE

org.apache.catalina.core. StandardHostValve.ACCESS_SESSION org.apache.catalina.STRICT_SERVLET_COMPLIANCE

在此处查看更多讨论,尤其是最后一篇:

See further discussion here, especially the last post:

http://tomcat.10.x6.nabble.com/Session-timeouts-ignore-quot-periodic-polling-quot-URL-td2159572.html

这篇关于定义自定义事件/操作/请求以在 Java Web App 中为会话超时重置计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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