惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - hone

管理 java学习 服务器相关 总统和亿万富翁经典语录(转载) js学习笔记 最近学习计划 VC控制Excel 真乱(转自csdn) 沟通(网上搜集) 工作 无题 将文档发送到打印机(From MSN) 经典68个故事 java的zip压缩(转自Jeet) 图形相关 在Oracle9i中计算时间差 六度分隔 经典故事 新年竟然第一篇?!
Manually Invalidating All Stale Sessions
hone · 2005-05-20 · via 博客园 - hone

 1import java.io.*;
 2import java.util.*;
 3import javax.servlet.*;
 4import javax.servlet.http.*;
 5
 6public class ManualInvalidateScan extends HttpServlet {
 7
 8  public void doGet(HttpServletRequest req, HttpServletResponse res)
 9                               throws ServletException, IOException {
10    res.setContentType("text/plain");
11    PrintWriter out = res.getWriter();
12
13    // Get the current session object, create one if necessary
14    HttpSession dummySession = req.getSession(true);
15
16    // Use the session to get the session context
17    HttpSessionContext context = dummySession.getSessionContext();
18
19    // Use the session context to get a list of session IDs
20    Enumeration ids = context.getIds();
21
22    // Iterate over the session IDs checking for stale sessions
23    while (ids.hasMoreElements()) {
24      String id = (String)ids.nextElement();
25      out.println("Checking " + id + "");
26      HttpSession session = context.getSession(id);
27
28      // Invalidate the session if it's more than a day old or has been
29      // inactive for more than an hour.
30      Date dayAgo = new Date(System.currentTimeMillis() - 24*60*60*1000);
31      Date hourAgo = new Date(System.currentTimeMillis() - 60*60*1000);
32      Date created = new Date(session.getCreationTime());
33      Date accessed = new Date(session.getLastAccessedTime());
34
35      if (created.before(dayAgo)) {
36        out.println("More than a day old, invalidated!");
37        session.invalidate();
38      }

39      else if (accessed.before(hourAgo)) {
40        out.println("More than an hour inactive, invalidated!");
41        session.invalidate();
42      }

43      else {
44        out.println("Still valid.");
45      }

46      out.println();
47    }

48  }

49}

50