public class SessionListener implements HttpSessionListener {
/* 监听session创建 */
public void sessionCreated(HttpSessionEvent event)
{
HttpSession session = event.getSession();
ServletContext application = session.getServletContext();
// 在application范围由一个HashSet集保存所有的session
HashSet sessions = (HashSet) application.getAttribute("sessions");
if (sessions == null) {
sessions = new HashSet();
application.setAttribute("sessions", sessions);
}
// 新创建的session均添加到HashSet集中
sessions.add(session); // 可以在别处从application范围中取出sessions集合 // 然后使用sessions.size()获取当前活动的session数,即为“在线人数”
System.out.println("创建seesion, 总连接数:" + sessions.size()); }
/* 监听session销毁 */
public void sessionDestroyed(HttpSessionEvent event)
{
HttpSession session = event.getSession();
ServletContext application = session.getServletContext();
HashSet sessions = (HashSet) application.getAttribute("sessions");// 销毁的session均从HashSet集中移除
if (sessions != null)
{
sessions.remove(session);
System.out.println("销毁seesion, 总连接数:" + sessions.size()); } } }
baseservice.query("select right0.name, right_action.actionurl from Right right0, RightUrl right_action where right0.id = right_action.right.id order by right_action.actionurl asc");
HQL语句:
ServletContext sc = event.getServletContext();
((SystemConfig) baseservice.query("select sysconfig from SystemConfig sysconfig where sysconfig = 'sysconfig00007'").get(0)).getValue();
baseservice.query("from SystemOption s where s.parent.id = 'sysoption00001' and s.isAvailable = 1 order by s.id asc");
/* 获取客户端请求的url */
String url = request.getRequestURI();
/* 获取客户端请求的url */
String url = request.getServletPath();