3 Replies Latest reply on May 30, 2004 3:45 PM by neptune5

    Stateful session bean Problem

    neptune5 Newbie


      Trying to create a servlet that communicates with a orderbean - thats stateful.

      This is supposed to maintain conversational state right between client right ? do I need a degree in rocket science to get this to work then
      situation below:

      client 1 --------------> sessionbean 1 --------------> order no 1

      client 2----------------> session bean 2----------------> orderno2

      if i add an item to order 1 on client 1 it actually adds it to order 2

      I've followed books etc so far and am lost on this anyone point out a decent tutorial or I could send the relevant files would someone have a look ?

      Regards Adrian

        • 1. Re: Stateful session bean Problem
          Scott Stark Master

          You have to key the SFSB1 with client1 using the unique session id of client1 to ensure that your not mixing invocations from the clients. I assume your using the HttpSession to do this as follows:

           protected void doRequest(HttpServletRequest req, HttpServletResponse res)
           throws ServletException, IOException
           HttpSession session = req.getSession();
           SFSB bean = (SFSB) session.getAttribute("OrderBean");
           if( bean == null )
           // Create the bean...

          There are thread synchronization issues you have to take care of here since multiple requests can be active here, include within the same session depending on the client.

          • 2. Re: Stateful session bean Problem
            Holger Baxmann Novice

            The servlet it stateless, it does not know about client1 and order1. If client1 and order1 does not agree about the same attribute to identify the workflow (the session) things get mixed up in the servlet.


            • 3. Re: Stateful session bean Problem
              neptune5 Newbie

              cheers Scott i'll give it another try. I did put some similar code into the doGet() with the httpsession . Problem was when I add the item it goes through the doPost() and this part lost the bean and couldn't retrieve the order no to get the order details.

              Does putting this code into a doRequest() get round this problem or have I got my design wrong. I only go thriough the doget once at the start. The form loads to add items to the order which then goes through the doPOst. Theres a complete button which then raises the status . Then we have to click a new order button, which again goes through doPOst().

              Hope this helps too.
              Regards Adrian