Stateful Session Bean and HTTP Session

后端 未结 1 1667
终归单人心
终归单人心 2021-01-06 09:18

Is there any relationship between stateful session bean and HTTP session ? What are the use cases where we would require a stateful session bean and what use cases requires

相关标签:
1条回答
  • 2021-01-06 10:01

    HTTP is a stateless protocol Which means that it is actual transport protocol between the server and the client -- is "stateless because it remembers nothing between invocations
    Now First read this what is HTTPSession and what is Session Bean (keep in mind that session beans are use to maintain the data state across multiple request so mostly a session bean is a stateful session bean because it holds data across whole session)

    HTTP Session
    An HttpSession object can hold conversational state across multiple requests from the same client. In other words, it persists for an entire session with a specific client. We can use it to store everything we get back from the client in all the requests the client makes during a session.
    Session Bean from wiki
    In the Java Platform, Enterprise Edition specifications, a Session Bean is a type of Enterprise Bean.A session bean performs operations, such as calculations or database access, for the client. Although a session bean can be transactional, it is not recoverable should a system crash occur. Session bean objects either can be stateless or can maintain conversational state across methods and transactions. If a session bean maintains state, then the EJB container manages this state if the object must be removed from memory. However, the session bean object itself must manage its own persistent data.

    In Simple words
    Session tracking is the process of maintaining information, or state, about Web site visitors as they move from page to page. It requires some work on the part of the Web developer since there's no built-in mechanism for it. The connection from a browser to a Web server occurs over the stateless Hypertext Transfer Protocol (HTTP)
    AND
    SFSB's are designed for managed client state over multiple calls to the same session bean (i.e. a conversation). If you look at JBoss Seam, you will see that there is very heavy use of SFSB's for conversation context.
    In EJB3, there is no such thing as "stateless is better than stateful session beans". For example, one provides a service like a credit card processor (stateless) and one provides processing for a multi-screen wizard use case (stateful).

    In My opinion Managing state using HttpSession and stateless session beans is very difficult and problematic.

    EDIT: HTTPSession is use to keep the session tracking like A user session
    For example You want to create a Login , Logout mechanism then You must need the HTTPSession because when The user will start navigation between different pages then this HTTPsession will remember that WHO is asking for the pages otherwise it is not possible(because HTTP is a stateless protocol)
    Now In session you just set the session of username and password and you are checking on every page that if this session exists then show the page

    Now what if , You have to send a lot of information of this user across multiple requests? In this scenario, You will set all this info in a Stateful session bean
    But now a days , In modern frameworks session as well as information , everything is stored in Session beans because From session bean it is easy to manage them.
    HTTPSession was used when we were purely on Servlet and somehow JSP technologies

    0 讨论(0)
提交回复
热议问题