【问题标题】:Embedded jetty implementing HttpSessionListener实现 HttpSessionListener 的嵌入式码头
【发布时间】:2013-07-19 17:27:31
【问题描述】:

我正在尝试使用带有代理 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 不为空,没有触发会话创建事件,请帮助我,获取会话事件的过程是什么?

【问题讨论】:

    标签: jetty embedded-jetty


    【解决方案1】:

    你应该有一个 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");
    

    【讨论】:

      猜你喜欢
      • 2011-07-12
      • 2011-09-30
      • 2013-12-26
      • 2014-02-25
      • 2019-09-25
      • 2016-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多