我想知道当前的方法是关于使用JSF 2.0(如果存在任何组件)和Java EE 6核心机制(登录/检查权限/注销)的Web应用程序的用户身份验证,其中包含用户信息保存在JPA中实体.Oracle Java EE教程在这方面有点稀疏(仅处理servlet).
这没有使用整个其他框架,如Spring-Security(acegi)或Seam,但如果可能的话,试图用新的Java EE 6平台(Web配置文件).
在我之前的问题中, 我遇到了从登录表单显示验证消息的问题。该问题现已解决,但这次我无法显示带有FacesContex#addMessage.
使用 JSF + PrimeFaces。
<p:dialog header="Login" widgetVar="loginDlg">
<h:form id="loginForm">
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginBean.username}" id="username" required="true" label="username" />
<p:message for="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret value="#{loginBean.password}" id="password" required="true" label="password" />
<p:message for="password" />
<f:facet name="footer">
<p:commandButton value="Login" id="loginDlgButton" update=":loginForm,:welcomeMsg" actionListener="#{loginBean.login}"
oncomplete="handleLoginRequest(xhr, status, args)"/>
<p:message for="loginDlgButton" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
在LoginBean (a SessionScoped ManagedBean) 中:
public void login() {
FacesContext context = FacesContext.getCurrentInstance();
RequestContext rContext = RequestContext.getCurrentInstance();
HttpServletRequest …Run Code Online (Sandbox Code Playgroud)