org.apache.catalina.ServerFactory.getServer()Tomcat 7中的等价物或者检索org.apache.catalina.Session实例的最佳方法是什么?
以下是用于处理Tomcat 6.0的示例代码:
public List<org.apache.catalina.Session> findActiveSessions() throws ServiceException {
StandardEngine engine = (StandardEngine) ServerFactory.getServer().findService("Catalina").getContainer();
StandardContext context = (StandardContext) engine.findChild(engine.getDefaultHost())
.findChild(ServletActionContext.getServletContext().getContextPath());
List<org.apache.catalina.Session> list = new ArrayList<org.apache.catalina.Session>();
for (org.apache.catalina.Session session : context.getManager().findSessions()) {
list.add(session);
}
return list;
}
Run Code Online (Sandbox Code Playgroud) tomcat7 ×1