Servlet的HttpSession 和EJB的Stateful session 都是维持客户端状态, 那么哪个最好?看看下面的优缺点:
1 . Stateful session bean
Advantages :
It supports transaction service ,security service, life cycle management, RMI, instance cache, thread safe etc. You need not write code for these services.
It can be used by both web based and non web based clients (like swing etc.) .
It can be used for multiple operations for a single http request.
Disadvantages :
Since it supports a number of services mentioned above it takes more time to process a request.
2. HttpSession object
Advantages:
It is a simple java object (perhaps a Hashtable) and takes very less time and resources to maintain a client state
Disadvantages:
It does not support the features discussed above
It cannot process multiple operations for a single http request.
So depending on your application's requirement you can choose the one best suited for you, if you want the bean only for client state management then HttpSession object gives better performance than Stateful session bean.