Session Beans

Discussion in 'Java' started by Sachin, Nov 4, 2005.

  1. Sachin

    Sachin Guest

    I am implementing a shoping cart apllication using ejb stateful session
    beans as an excercise in learning ejb. I use a jsp page as the client.
    I use sun system application server. My problem is, when the web server
    use the same JSP instance to handle multiple requests for the same jsp
    page, same state of the bean instance may be shared among multiple
    clients. So this can produce wrong results and how i avoid this? Please
    help me.
     
    Sachin, Nov 4, 2005
    #1
    1. Advertisements

  2. Sachin

    Bryce Guest

    On 4 Nov 2005 02:18:01 -0800, "Sachin" <> wrote:

    >I am implementing a shoping cart apllication using ejb stateful session
    >beans as an excercise in learning ejb. I use a jsp page as the client.
    >I use sun system application server. My problem is, when the web server
    >use the same JSP instance to handle multiple requests for the same jsp
    >page, same state of the bean instance may be shared among multiple
    >clients. So this can produce wrong results and how i avoid this? Please
    >help me.


    Strange, shouldn't be happening... What does your JSP page look like?
    are your variables static? Are you putting the beans in application
    scope instead of session?

    --
    now with more cowbell
     
    Bryce, Nov 4, 2005
    #2
    1. Advertisements

  3. Sachin

    HalcyonWild Guest

    Bryce wrote:

    > On 4 Nov 2005 02:18:01 -0800, "Sachin" <> wrote:


    >
    > >I am implementing a shoping cart apllication using ejb stateful session
    > >beans as an excercise in learning ejb. I use a jsp page as the client.
    > >I use sun system application server. My problem is, when the web server
    > >use the same JSP instance to handle multiple requests for the same jsp
    > >page, same state of the bean instance may be shared among multiple
    > >clients. So this can produce wrong results and how i avoid this? Please
    > >help me.


    >
    > Strange, shouldn't be happening... What does your JSP page look like?
    > are your variables static? Are you putting the beans in application
    > scope instead of session?




    I too got thinking about it.

    Only one instance of the compiled servlet class of the JSP runs in the
    container's memory. So, multiple requests to the server would mean, the
    same java class(of the jsp) executing, via multiple threads. If the Jsp
    has data members, they can be corrupted. Even though, different
    stateful EJB exist for different requests, the JSP instance remains the
    same.

    Is it a good practice to avoid private data members in JSP and
    servlets. I have never seen anything like that. ( Looking at existing
    code gives a very good idea of how to use stuff ).

    What if your JSP has private data members? Will it have every chance of
    inconsistent data.

    By the way, to be safe, do not call the EJB directly from the JSP. Use
    a delegate, a simple java class instantiated for every call to the JSP,
    which in turn handles the EJB, and returns data back to JSP.
     
    HalcyonWild, Nov 7, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kabal
    Replies:
    0
    Views:
    1,094
    Kabal
    Jul 22, 2003
  2. MP
    Replies:
    2
    Views:
    2,813
    John C. Bollinger
    Nov 11, 2003
  3. TT \(Tom Tempelaere\)

    Server side context for session beans

    TT \(Tom Tempelaere\), Jan 28, 2004, in forum: Java
    Replies:
    1
    Views:
    373
    TT \(Tom Tempelaere\)
    Jan 29, 2004
  4. Mark
    Replies:
    2
    Views:
    4,525
    Vinsan
    Feb 18, 2004
  5. John Smith
    Replies:
    2
    Views:
    2,406
    Sampsa Sohlman
    Jul 15, 2004
  6. davout
    Replies:
    0
    Views:
    403
    davout
    Dec 7, 2004
  7. Torsten Schmeissel
    Replies:
    0
    Views:
    612
    Torsten Schmeissel
    Apr 29, 2005
  8. Sachin

    EJB Stateful Session Beans

    Sachin, Nov 4, 2005, in forum: Java
    Replies:
    0
    Views:
    548
    Sachin
    Nov 4, 2005
Loading...