本文介绍了如何在GlassFish中的JSF服务中获取登录用户的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GlassFish上有一个JSF应用程序。它的设计是这样的:
$ b $ user.xhtml> UserHandler.java> UserService.java> UserDAO.java> database



我知道在UserHandler中,我可以使用FacesContext获取登录的用户名。



我的问题是,在UserService内部(它与JSF查看)如何在不使用FacesContext的情况下获取登录用户的名称?



我不想从服务内部引用FacesContext,因为将来可能会从Web服务或备用视图技术访问服务。

或者,我可以将登录用户的名称传递给Service中的每个方法,但我宁愿不这样做,或者仅仅因为它看起来有点笨拙。



任何建议都非常感谢!
Rob

解决方案


I have a JSF app on GlassFish. It's designed like so:

user.xhtml > UserHandler.java > UserService.java > UserDAO.java > database

I know that in the UserHandler, I can get the logged in user name using the FacesContext.

My question is, inside the UserService (which is decoupled from the JSF view) how can I get the name of the logged in user without using FacesContext?

I don't want to reference FacesContext from inside the service because it's possible in the future that the service will be accesses from a webservice or alternate view technology.

Alternately, I can pass in the name of the logged in user to each method in the Service, but I prefer not to do that either just because it seems a little kludgy.

Any suggestions are greatly appreciated!Rob

解决方案

javax.servlet.http.HttpServletRequest#getRemoteUser

这篇关于如何在GlassFish中的JSF服务中获取登录用户的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:58