Originally posted by veena madhukar:
It has been confusing. As everytime when i see a question on the use of servlet Vs. Stateful session bean.
For eg in the following example my preference is to use Stateful session bean to manage users session over Servlet. As this is a classic shopping cart ex. let me know as the mock test had to suggest serlvet usage here.
You are developing an online shopping store for an art gallery. The company aims to bring fine art to the masses and expects a huge volume of traffic through the site. The site allows customers to pay for goods and arrange delivery methods using credit cards.
Veena,
The question about which type of technology use for maintain users session state depends of the non functional requirements of your application.
In yours example, you could see that the application must be used for a huge volume of traffic. This means that you have to implement 'SCALABILITY'.
Another point is, The site allows customers to pay for goods and arrange delivery methods using credit
cards. This means that you must ensure 'TRANSACTIONAL BEHAVIOR'.
Those two points refers to the use of enterprise beans, since they can provide this benefits for the application. EJB�s by specification ensures scalability and transactional behavior.
Web Containers can offers transactions using JTA, but scalability is a specific vendor feature. And of course, even having open-source web containers as
tomcat, jonas,
jboss, geronimo that providers those features, you can�t design an solutions that depends of an specific product to works. An architect must ensure that your solution is vendor independent. So, EJB�s (SFSB) are very recommended for this situation.
If you do not need any of this non functional requirements to maintain users sessin state, you can easly use the HttpSession object and maintain those references in the web tier. You can even, use the both approachs together.
Use the HttpSession is easier to the programmer, since there is no special technology to use, just call the HttpSession.setAttribute() method. But, the HttpSession is dangerous in an heterogeneous environment. The HttpSession clustering is much more expensive rather SFSB clustering, because, in the SFSB cluster, only the state must be moved between JVM�s. In the HttpSession cluster, the entire HashMap (collection of references) must be copied between JVM�s, and you need to ensure that every object maintained in the HttpSession, implements the java.io.Serializable interface.
You see, the 'simpliest' approach offered by the HttpSession defines much more work to ensure scalability, over the simpliest and ensured stateful session beans.
I hope have helped you !