Refactor session listeners and integrate them into servlet code