cancel
Showing results for 
Search instead for 
Did you mean: 

EJB Stateful bean and create method in the jspInit()

Former Member
0 Kudos

Maybe someone can help me to understand:

1) I create a stateful EJB with a single business method (incrCounter) and the respective getCounter().

2) in my JSP page, i create the EJB in the jspInit() and in the code i call the method incrCounter(), then I display the result of getCounter()

I deploy ok.

Now if I click refresh 8 times in the browser pointing to the page, i see the counter increasing let's see to 8.

If my collegue browse with his browser to the same page ... he also see the counter increasing starting from 9 - if he refresh 10 times then he sees 19. On my browser ofcourse the counter is still 8.

If now i refresh ... i get to 20.

Looks like me and my colleque are sharing the same session and of course pointing to the same EJB instance !

So the question is: what is wrong ? I was thinking that J2EE is managing the sessions for me, that means:

For each new session call the jspInit() and allocate a new bean.

Looks like

jspInit() is called once for all the sessions. So only one Bean is created in the jspInit().

Can someone explain me how to generate the behavior: new client sessions generates a new Bean ? Is this a J2ee setup issue or a deployment issue ?

And: how to reassociate a http request with a client session ? is this automatic or do i need to call some method from Jsp ?

Thanks

Matteo

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Well I reply to myself:

Unless you set the cookie property in web-j2ee-engine.xml to SESSION, JSP will not attach itself to the previous session, but always generate a new one.

Thanks

Matteo