我使用Glassfish服务器3.1.1,并且为用户组成功配置了我的领域.
I use Glassfish server 3.1.1, and I successfully configured my realm for the usergroups.
虽然仅登录了一个用户,但一切正常,但是当我使用来自其他浏览器(甚至是不同计算机)的另一个帐户登录时,将清除第一个会话,最后一个登录的用户数据显示在以前的每个会话.
While only 1 user is logged in, everything works fine, but as I log in with another account from a different browser (or even a different computer), the first session is cleared and the last logged in users data is shown in every previous sessions.
我正在使用Netbeans,并让它从postgreSQL数据库生成我的实体类,然后从这些实体生成JSF页面. 我读过有关HttpSessions的信息,但我没有一清二楚.我应该继续这种方式,还是解决方案朝着不同的方向发展?如果这是正确的方法,那么有人可以给我发送示例源吗?
I'm using Netbeans, and I let it generate my entity classes from a postgreSQL database, then the JSF pages from the entities. I read about HttpSessions, but there wasn't everything clear to me. Shall I continue this way, or the solution is in a different direction? If this is the right way, could anyone send me a sample source?
这是我的代码:
Login.xhtml:
Login.xhtml:
<h:inputText id="email" size="25" value="#{login.email}" maxlength="30"/> <h:inputSecret id="password" size="25" value="#{login.password}" maxlength="100"/> <h:commandLink value="Bejelentkezés" action="#{login.loginAction}"/>这是我的登录类的样子:
This is how my login class looks like:
@ManagedBean(name="login") @RequestScoped public class LoginBean { private String email; private String password; public String loginAction() { HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance() .getExternalContext().getRequest(); try { System.out.println("login with: " + email + ", " + password + "."); req.login(email, password); } catch(ServletException e) ....推荐答案
到目前为止发布的代码看起来还不错.
The code posted so far looks fine.
,但是当我从其他浏览器(甚至是另一台计算机)使用另一个帐户登录时,第一个会话将被清除,而最后一个登录的用户数据将在之前的每个会话中显示.
此问题是由到目前为止所发布的代码之外的其他地方引起的.完全不应清除该会话.这可能是对这种情况的误解.也许您不理解会话"的概念.这些症状表明您显然在某些static变量或@ApplicationScoped托管bean中抓住了登录用户.确保您没有这样做.
This problem is caused elsewhere than in the code posted so far. The session should not be cleared at all. This is likely a misinterpretation of the happening. Perhaps you don't understand the concept "session". The symptoms indicate that you're apparently getting hold of the logged-in user in some static variable or an @ApplicationScoped managed bean. Make sure that you aren't doing that.
关于会话"的工作方式,请阅读以下内容: servlet如何工作?实例化,会话,共享变量和多线程.
As to how the "session" works, please read this: How do servlets work? Instantiation, sessions, shared variables and multithreading.
关于如何选择适当的托管bean范围,请阅读以下内容:如何选择正确的bean作用域?
As to how to choose the proper managed bean scope, please read this: How to choose the right bean scope?
更多推荐
Java Web应用程序多用户会话处理
发布评论