如何在jsf 2.0中登录用户ID
我无法获取用户ID。我尝试了以下方法。
xhtml页面
<h:outputText value="#{request.remoteUser}"></h:outputText>
<h:outputText value="#{userDetails.userId}"></h:outputText>
Viewscoped bean class。
public String getUserId() {
FacesContext ctx = FacesContext.getCurrentInstance();
System.out.println ("User"+ctx.getExternalContext().getRemoteUser());
userId =ctx.getExternalContext().getRemoteUser();
return userId;
}
我应该在web.xml中进行任何初始化吗?或者我的bean类是否应该扩展或实现任何其他类?