正如所料,登录页面在请求受保护/安全资源时加载:
<login-config>
<auth-method>FORM</auth-method>
<realm-name>jdbc</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/login.xhtml</form-error-page>
</form-login-config>
</login-config>
Run Code Online (Sandbox Code Playgroud)
我知道j_security_check如果身份验证成功,它将自动转发到受保护/安全资源:
<form method="post" action="j_security_check">
<input type="text" name="j_username">
<input type="password" name= "j_password">
</form>
Run Code Online (Sandbox Code Playgroud)
不过,我想允许用户注册(或登录)继续这样我用JSF 2.0: <h:form...,EL: #{loginBean.register()}...等...而我从Servlet 3.0编程验证:
public void register() {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
try {
// Register...
request.login(this.username, this.password);
// Redirect to the protected/secure resource...
} catch (ServletException e) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何找出最初请求的资源是什么?可能是: