The sessionCreated of the HttpSession event listener is not executed

the number of online users needs to be counted in the project, and the sessionCreated that uses HttpSessionListener,LoginController to call request.getSession (), HttpSessionListener event listeners is not executed.

related codes

@WebListener
public class SessionListener  implements HttpSessionListener, HttpSessionAttributeListener {

    public static final Logger logger = LoggerFactory.getLogger(SessionListener.class);

    /**
     * session
     */
    public int count = 0;

    public SessionListener(){

        logger.info("SessionListener......");
    }

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        logger.info("===============sessionCreated===============");
        System.out.println("HttpSessionListenercountPP  ");
        countPP;
        httpSessionEvent.getSession().getServletContext().setAttribute("count", count);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        logger.info("===============sessionDestroyed===============");
        System.out.println("HttpSessionListenercount--  ");
        count--;
        httpSessionEvent.getSession().getServletContext().setAttribute("count", count);

    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {
        System.out.println("1111111111111111111111111111");
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {
        System.out.println("222222222222222222222222222222");
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {
        System.out.println("333333333333333333333333333333333");
    }

when the project starts, the printed SessionListener., indicates that the listener class has been initialized and the listener has been called.

Apr.09,2021

print SessionListener. It only means that the listener is summed up by the spring container because you are in the constructor.
after writing a @ WebListener class. You also need configuration to configure this monitor

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e46602-4315d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e46602-4315d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?