Before user login, if type xxx.detail.jsf
, it will redirect to the login page let user login. This task has been done already. How can I make it to redirect back to the xxx.detail.jsf
after the user successfull login?
I'm using Eclipse Indigo, Tomcat 7 and Mojarra 2.0.3.
To redirect users to a specific page after login, you can simply add the redirect URL parameter in login form Shortcode. The redirect_url parameter allows you to redirect to a certain page after the user is logged in.
During a user's authentication, the redirect_uri request parameter is used as a callback URL. This is where your application receives and processes the response from Auth0, and is often the URL to which users are redirected once the authentication is complete.
WP Login and Logout RedirectUpon installation, you'll find the new Redirect Options menu in your sidebar. Click it, and you'll see two boxes: Login Redirect URL and Logout Redirect URL. Put the URL you want in and click Save Changes, and you're done. Redirect options in the WP Login and Logout Redirect plugin.
At the point when you're redirecting to the login page, you need to save the current request URI. You're likely using a Filter
to perform the login check and the redirect. In that case, you can use HttpServletRequest#getRequestURI()
to obtain the current request URI:
String requestURI = request.getRequestURI();
You could either pass it as a request parameter in the redirect URL or store it in the session. Passing as a request parameter is the safest:
response.sendRedirect(request.getContextPath() + "/login.jsf?from=" + URLEncoder.encode(requestURI, "UTF-8"));
In the bean associated with the login page, you could set it as a managed property or a view parameter. Let's assume that the bean is view scoped so that you can perform nice ajax actions/validations and like. In that case, the view parameter is the only neat way:
<f:metadata>
<f:viewParam name="from" value="#{login.from}" />
</f:metadata>
Then, when the real login succeeds, you can redirect to that URI by ExternalContext#redirect()
:
public void login() throws IOException {
// ...
FacesContext.getCurrentInstance().getExternalContext().redirect(from);
}
(if necessary supply a default target for the case that from
is null
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With