java web 多用户,Java Web应用程序多用户会话处理

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.

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?

Here is my code:

Login.xhtml:

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.

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.

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.

As to how to choose the proper managed bean scope, please read this: How to choose the right bean scope?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值