/** * * @author cirstea */ @WebServlet(name = "ControllerServlet", urlPatterns = {"/submitTicket"}) public class ControllerServlet extends HttpServlet { ... // key for retrieving the bean in the session private static final String STATEFUL_TEST_BEAN_KEY = "STATEFUL_TEST_BEAN_KEY"; ... private TicketManager getStatefulBean(HttpServletRequest request) throws ServletException { HttpSession httpSession = request.getSession(true); TicketManager ticketManager = (TicketManager) httpSession.getAttribute(STATEFUL_TEST_BEAN_KEY); System.out.println("TicketManager = " + ticketManager); if (ticketManager == null) { try { InitialContext ic = new InitialContext(); ticketManager = (TicketManager) ic.lookup("java:global/GestionPersonnes/GestionPersonnes-ejb/TicketManagerBean"); httpSession.setAttribute(STATEFUL_TEST_BEAN_KEY, ticketManager); } catch (NamingException e) { throw new ServletException(e); } } return ticketManager; } private void invalidateSessionTicket(HttpServletRequest request) { HttpSession httpSession = request.getSession(true); httpSession.setAttribute(STATEFUL_TEST_BEAN_KEY, null); } ... }