English 中文(简体)
如何在任何特定时刻确定我以服务器为基础的应用在哪些公开会议上处理
原标题:How to find out what open sessions my servlet based application is handling at any given moment

我需要写一份普通照会,在接到通知后,将获得关于目前开幕会议名单的信息。

是否有办法这样做?

最佳回答

<http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionListener.html>rel=“nofollow noretinger”>HttpSessionListener>>>a>>,给它一个static Set<HttpSession> property,在sessionCreated ()期间,删除了该编码在<>Destroyed(电话)/打上。 现在,你召集了一个班级,在目前收集的博览会上举行所有公开会议。 这方面的一个基本实例是:

public HttpSessionCollector implements HttpSessionListener {
    private static final Set<HttpSession> sessions = ConcurrentHashMap.newKeySet();

    public void sessionCreated(HttpSessionEvent event) {
        sessions.add(event.getSession());
    }

    public void sessionDestroyed(HttpSessionEvent event) {
        sessions.remove(event.getSession());
    }

    public static Set<HttpSession> getSessions() {
        return sessions;
    }
}

之后,在你的职责中,我们就做了以下工作:

Set<HttpSession> sessions = HttpSessionCollector.getSessions();

如果你想在申请范围内储存/提出,以便你能够制作<代码>Set<HttpSession>non-static,则请上。 HttpSessionCollector 实施http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextListener.html” rel=“nofollow noreferer”>ServletContextstener ><>>>>>>>>>>>>>m>as well<>/em>,基本上添加以下方法:

public void contextCreated(ServletContextEvent event) {
    event.getServletContext().setAttribute("HttpSessionCollector.instance", this);
}

public static HttpSessionCollector getCurrentInstance(ServletContext context) {
    return (HttpSessionCollector) context.getAttribute("HttpSessionCollector.instance");
}

您可在《服务手册》中使用:

HttpSessionCollector collector = HttpSessionCollector.getCurrentInstance(getServletContext());
Set<HttpSession> sessions = collector.getSessions();
问题回答

也许使用联合数据交换的元件更为可取,不需要密码。 仅读作价值

数据:jbos.web: 类型=Manager,path=/myapplication,host= Localhost”活性决定因素





相关问题
Can t access locally hosted project via the internet?

I m currently developing a Java Servlet Project in Eclipse. The project is compiled via Tomcat 5.5 and hosted in localhost:8080(alternatively 127.0.0.1:8080 AND 192.168.1.10:8080 which also happens ...

JSP programmatically render

I need to programmatically render JSP page. As far as I understand, JSP should have some compiler. The question is can I use this compiler dirrectly without JspServlet and others? All I need is ...

Javascript redirect

I am working with javascript and here is what I am trying to do: 1. Send a get request which looks like "http://localhost:8080/myapp/verify.htm?verifyId=Agkvhs" My requests reaches my verify.jsp in ...

热门标签