Login with Hibernate and store username logged

后端 未结 1 981
失恋的感觉
失恋的感觉 2021-01-16 23:35

I\'m developing a simple project cloud in which a registered user after login can download and upload files. I\'m developing with Eclipse Java EE, JSF and Hibernate. In my p

1条回答
  •  有刺的猬
    2021-01-17 00:17

    You need to create a ManagedBean of session scope. On login, you set the user object (that you got from DB) in that ManagedBean. And then, you will be able to access it through all the application.

    Alternative way, is to set the user object directly in session:

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    Map sessionMap = externalContext.getSessionMap();
    

    And then:

    sessionMap.put("attributeName", whateverYouWantToSaveInSession);
    

    But I would choose the first approach.

    0 讨论(0)
提交回复
热议问题