有没有办法从 EJB 模块访问 HttpSession?
我目前需要获取会话 ID,因此我需要获取 HttpSession,但我的 EJB 模块中没有任何 servlet。那么也许像 webservices api 中的一些 DI 注释?
I'm currently in a need of getting session ID thus I need to get the HttpSession but I don't have any servlets in my EJB module. So perhaps some DI annotation like in webservices api?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EJB 技术不依赖于 HTTP,因此绝对没有理由在 EJB API 中包含 HTTP 特定的内容。如果您需要来自 EJB 的会话 ID(想知道为什么),请将其作为参数从 Web 层传递(从技术上讲,您甚至可以将引用传递给
HttpRequest
或HttpSession
对象并从 bean 中读取它,但这将是一个可怕的、错误的、异端的设计,EJB 不应该遵守 Servlet API)。您也许应该澄清您的要求。The EJB technology doesn't rely on HTTP so there is absolutely no reason to have HTTP specific stuff in the EJB API. If you need the session id from an EJB (wondering why), pass it as parameter from the web tier (technically, you could even pass the reference to the
HttpRequest
or theHttpSession
objects and read it from the beans but that would be an horrible, wrong, heretic, etc design, EJBs shouldn't have adherences to the Servlet API). You should maybe clarify your requirement.