Hello!
Trying to do something like session beans. But the application works unpredictably. A servlet is like this:
@WebServlet(name = "MyServlet", urlPatterns = {"/goservlet.jsp"}) public class MyServlet extends HttpServlet { @EJB private MySessionBean mySessionBean; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("Устанавливаем параметр. Текущий=" + mySessionBean.getStr1()); mySessionBean.setStr1(request.getParameter("xaction")); response.sendRedirect("/zapros.jsp"); } ... ... ...
Bean I have Stateful
:
@Stateful(name = "MySessionEJB") public class MySessionBean { private String str; ...
It seems that all sessions should have their own MySessionBean
object. But when debugging, when requests are sent from a different computer to a server for this servlet, then the same MySessionBean
object is used for one session and for another session (for one and the second user). Namely, if one user changes the field of an object, then another user will experience the same changes. Correct me if I am mistaken or tell me what the error is.