会话超时 计算机术语,Servlet会话超时(Servlet Session timeout)

司徒博容
2023-12-01

Servlet会话超时(Servlet Session timeout)

我正在写我的SPring MVC网络应用程序。

我已将会话时间设置为10080分钟,等于1周。 现在我想让用户在每次打开浏览器时都登录:

sessionService.setcurrentUser(myuser);

HttpSession session = request.getSession();

Cookie cookie = new Cookie("JSESSIONID", session.getId());

cookie.setMaxAge(timeout);

response.addCookie(cookie);

我的Cookie Max Age应该与会话超时一样吗?

cookie.setMaxAge(10080);

这是不错的做法吗?

I'm writing my SPring MVC web application.

I have set my session time out to be 10080 minutes equal to 1 week. Now I would like to keep user logged in every time he open browser:

sessionService.setcurrentUser(myuser);

HttpSession session = request.getSession();

Cookie cookie = new Cookie("JSESSIONID", session.getId());

cookie.setMaxAge(timeout);

response.addCookie(cookie);

Should my cookie Max Age be the same as session time out?

cookie.setMaxAge(10080);

Is it good practice?

原文:https://stackoverflow.com/questions/4122176

2020-01-07 21:26

满意答案

您使用cookie来引用您的会话ID。 如果Cookie的超时时间低于会话,则不会再找到您的会话。 因此,将您的Cookie超时设置为至少会话超时是明智的。

You use cookies to refer to your session id. If the timeout of the cookie is lower than the session, it will not find your session anymore. So setting your timeout of your cookie to at least the timeout of your session is advisable.

相关问答

如果您默认允许长会话超时,则风险在共享计算机上 - 将来的用户访问当前用户的会话。 如果你试图责怪用户没有注销,那么你会发现你的用户群减少了,你将不得不处理很多最终用户的投诉。 最佳做法是默认情况下具有短暂超时,但允许选项“在此设备上记住我”,以便人们可以选择长会话(如果他们在受信任的环境中)。 黄金法则是“ 默认安全 ”。 If you by default allow long session timeouts, then the risk is on shared computers - f...

尝试ng-idle。 它是一个简单的组件,您可以在达到超时之前设置超时和警告时间。 然后,您可以查询服务器以进行用户注销或类似的操作。 myApp.config(function(IdleProvider, KeepaliveProvider) {

IdleProvider.idle(900); // 15 min

IdleProvider.timeout(60);

KeepaliveProvider.interval(600); // heartbeat every 10 min

...

首先,存储用户最后一次提出请求 <?php

$_SESSION['timeout'] = time();

?>

在随后的请求中,检查他们以前提出的请求(在本例中为10分钟) <?php

if ($_SESSION['timeout'] + 10 * 60 < time()) {

// session timed out

} else {

// session ok

}

?>

first, store the last time the user made a...

是。 JSF应用程序的会话超时也在web.xml中设置。 实际上,JSF利用Java Servlet来处理http请求和响应。 Yes. Session timeout for JSF applications is set in web.xml too. In fact JSF makes use of Java Servlets to handle http requests and responses.

您使用cookie来引用您的会话ID。 如果Cookie的超时时间低于会话,则不会再找到您的会话。 因此,将您的Cookie超时设置为至少会话超时是明智的。 You use cookies to refer to your session id. If the timeout of the cookie is lower than the session, it will not find your session anymore. So setting your timeout of your ...

默认20分钟,每个请求重置 Include this in you web.config file:

请再次访问此论坛: http://forums.asp.net/t/1283350.aspx default 20 minutes which is reset with each request Include this in you web.config file:

为什么不直接将登录时间保存为首选变量? 请注意,这不是一种实现会话的安全方式,但由于您不提供更多信息,因此我无法提供更多详细信息,以便更好地解决问题 Why don't you just save the time on login as a preference variable? Note that this is not a safe way to implement sessions, but since you dont provide more Information i cant g...

如果会话过期,那么会话将被垃圾收集 调用该方法时,httpServletRequest.getRequestedSessionId()将返回新值。 请查看以下网址 http://download.oracle.com/docs/cd/E17802_01/products/products/servlet/2.1/api/javax.servlet.http.HttpServletRequest.html#getRequestedSessionId%28%29 if the session got ...

空闲超时适用于整个应用程序池。 如果连接到池的所有应用程序在设定的时间内没有任何活动,它就会启动。 会话状态是每个会话。 这是专门针对单个用户会话的。 您可以在任何时间进行多次会话。 Idle timeout is for the application pool as a whole. It kicks in if all the applications linked to the pool have had no activity within the set time. Session s...

你确定会话已达到超时吗? 根据您的问题,如果会话仍然存在,我认为会话尚未达到超时。 会话有一生。 会话生命周期可以在名为php.ini的文件中看到 在该文件中,您可以在var session.gc_maxlifetime的值中找到会话生存期的长度。 您可以按照以下链接中的步骤设置/更改会话生存期如何更改PHP中的会话超时? ======更新====== 根据您的评论,如果用户在长时间处于非活动状态时尝试加载页面,则可能是您没有创建代码来注销用户 你必须在每个.php文件中“创建代码来检查会话时间并...

相关文章

有2个网站sit1和sit2.当一个用户进入sit1时,使用servlet的session对象跟踪它的

...

需求是这样的,程序中需要从session获取当前登录用户信息,来判断是否有权限继续执行,但是sessi

...

我要记录当前在线的人的人名的列表,把它放在application的一属性里了,在web.xml里配置了

...

微信公众平台开发教程(八)Session处理 在微信窗口,输入的信息有限,我们需要将一些信息分多次请

...

如题 一个页面可以得到两个不同action中的不同session.setAttribute(里面的值

...

Cactus是一个基于JUnit框架的简单测试框架,用来单元测试服务端Java代码。Cactus框架的

...

 类似资料: