Xpages - 获取活动会话数(Lotus Domino 8.5.2) [英] Xpages - Get number of active sessions (Lotus Domino 8.5.2)
问题描述
如何获取Xpage中的活动会话数。我正在尝试使用托管bean,但它只返回一个奇怪的字符串。这是简单的代码:
How do I get the number of active sessions in Xpage. I'm trying to use managed beans but it just returns a weird string. Here's the simple code:
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionCounterListener implements HttpSessionListener {
private static int totalActiveSessions;
public static int getTotalActiveSessions(){
return totalActiveSessions;
}
public void sessionCreated(HttpSessionEvent arg0) {
totalActiveSessions++;
System.out.println("sessionCreated - add one session into counter");
}
public void sessionDestroyed(HttpSessionEvent arg0) {
totalActiveSessions--;
System.out.println("sessionDestroyed - deduct one session from counter");
}
}
我是从 here 。但是当我调用 SessionCounterListener.getTotalActiveSessions()
时,它只返回0(无论是否有人登录)。
I got this from here. But when I call SessionCounterListener.getTotalActiveSessions()
, it only returns 0 (regardless if someone is logged in).
如果您有时间,可以查看我的测试数据库这里。
If you have the time, you can check out my test database here.
请帮帮我。非常感谢!
推荐答案
必须在应用程序中注入会话侦听器才能按需运行。否则,将永远不会调用sessionCreated / sessionDestroyed方法,并且始终返回0。但是XPages和传统JSF之间存在一些差异。看看这里:
A session listener must be injected in the application to get working as desired. Otherwise the sessionCreated/sessionDestroyed methods will never be called and 0is returned always. But there are some differences between XPages and "traditional" JSF. Have a look here:
或者查看< a href =http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=XSP%20Starter%20Kit =nofollow> XSP Starterkit 。
编辑:
要添加会话侦听器,请执行以下操作:
To add a session Listener, do the following:
- 切换到java透视图
- 在Code / Java文件夹中,创建一个文件夹META- INF
- 在此META-INF文件夹中,创建文件夹services
- 在services文件夹中创建名为com的文件。 ibm.xsp.core.events.SessionListener
- 在此文件中,添加类的全名:package.SessionCounterListener
- Switch to java perspective
- In the "Code/Java" folder, create a folder "META-INF"
- In this META-INF folder, create a folder "services"
- In the "services" folder create a file named "com.ibm.xsp.core.events.SessionListener"
- In this file, add the full name of your class: package.SessionCounterListener
现在,应激活会话监听器。
Now, the session listener should be activated.
这篇关于Xpages - 获取活动会话数(Lotus Domino 8.5.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!