有状态会话Bean和HTTP会话 [英] Stateful Session Bean and HTTP Session

查看:98
本文介绍了有状态会话Bean和HTTP会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有状态会话bean和HTTP会话之间是否存在任何关系?
我们需要有状态会话bean以及需要HTTP会话的用例有哪些用例。
我可以将有状态会话bean公开为一个宁静的Web服务吗?

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 HTTP Session. Can i expose a stateful session bean as a restful web service ?

推荐答案

HTTP是无状态协议这意味着它是服务器和客户端之间的实际传输协议 - 是无状态因为它在调用之间没有记住任何内容现在首先阅读这是什么是HTTPSession什么是Session Bean(请记住,会话bean用于维护跨多个请求的数据状态,因此大多数会话bean是有状态会话bean,因为它在整个会话中保存数据)


HTTP会话

HttpSession对象可以在来自同一客户端的多个请求中保持会话状态。换句话说,它会持续存在于特定客户端的整个会话。
我们可以使用它在客户端在会话期间发出的所有请求中存储我们从客户端返回的所有内容。

会话Bean 来自 wiki

在Java平台企业版规范中,会话Bean是一种Enterprise Bean。会话bean执行操作,例如计算或数据库访问,为客户端。虽然会话bean可以是事务性的,但如果发生系统崩溃,则无法恢复。会话bean对象可以是无状态的,也可以跨方法和事务维护会话状态。如果会话bean维护状态,那么如果必须从内存中删除该对象,则EJB容器将管理此状态。但是,会话bean对象本身必须管理自己的持久数据。


简单的单词

会话跟踪是指网站访问者在页面之间移动时维护信息或状态的过程。它需要Web开发人员的一些工作,因为它没有内置的机制。从浏览器到Web服务器的连接通过无状态超文本传输​​协议(HTTP)进行
AND

SFSB是为托管客户端设计的通过对同一会话bean的多次调用(即会话)来说明。如果你看一下JBoss Seam,你会发现SFSB对于会话上下文的使用非常繁重。
在EJB3中,没有无状态比有状态会话bean更好这样的东西。例如,一个提供像信用卡处理器(无状态)的服务,一个提供多屏幕向导用例(有状态)的处理。

在我看来管理状态使用HttpSession和无状态会话bean是非常困难和有问题的。


编辑: HTTPSession用于保持会话跟踪,就像用户会话一样

例如,您想创建一个登录,注销机制,那么您必须需要HTTPSession因为当用户将开始在不同页面之间导航时,此HTTPsession将记住WHO正在询问页面否则不可能(因为HTTP是无状态协议)
现在在会话中您只需设置用户名和密码,您正在检查每个页面,如果此会话存在,然后显示页面

现在如果,您必须跨多个请求发送此用户的大量信息?在这种情况下,您将在有状态会话bean中设置所有这些信息
但现在有一天,在现代框架会话和信息中,所有内容都存储在会话bean中,因为从会话bean可以很容易地管理它们。
当我们纯粹使用Servlet以及JSP技术时,使用了HTTPSession

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.

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

这篇关于有状态会话Bean和HTTP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆