4

我正在尝试使用带有代理 servlet 的嵌入式码头实现 HttpSessionListener 接口,我已经注册了 SessionListener,但它根本没有被调用,这是代码,

   public class JettyProxy {

    public static void main(String[] args) throws Exception {
        Server server = new Server();
        CustomProxyServlet customProxyServlet = new CustomProxyServlet();


        ServerConnector connector = new ServerConnector(server);
        connector.setPort(8888);
        server.addConnector(connector);

        ConnectHandler proxy = new ConnectHandler();

        server.setHandler(proxy);

        ServletContextHandler context = new ServletContextHandler(proxy, "/",
                ServletContextHandler.SESSIONS);
        ServletHolder proxyServlet = new ServletHolder(customProxyServlet);

        context.addServlet(proxyServlet, "/*");

        if (context.getSessionHandler() == null) {
            System.out.println("Session handler is null");
        } else {
            System.out.println("Session handler is not null");
        }

        if (context.getSessionHandler().getSessionManager() == null) {
            System.out.println("Managaer it null");
        } else {
            System.out.println("Manager is not null");
        }

        context.getSessionHandler().addEventListener(new CustomSessionHandler());

        server.start();
        server.join();
    }

}

SessionHandler 不为空,没有触发会话创建事件,请帮助我,获取会话事件的程序是什么?

4

1 回答 1

2

你应该有一个 SessionManager。我通常使用:org.eclipse.jetty.server.session.HashSessionManager.HashSessionManager() 和 org.eclipse.jetty.server.session.SessionHandler.SessionHandler(SessionManager manager)

那么你应该为上下文设置处理程序

context.setHandler(sessionHandler);

sessionHandler.addEventListener("Your Session Listener");
于 2014-02-12T13:40:50.210 回答