Session Beans

S

Sachin

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.
 
B

Bryce

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?
 
H

HalcyonWild

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,728
Latest member
FernMcmull

Latest Threads

Top