Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect back to the user desire access page after user login?

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.

like image 935
heng heng Avatar asked Jan 06 '12 01:01

heng heng


People also ask

How do I redirect a user to a page after login?

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.

How do I redirect after authentication?

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.

How do I redirect a homepage to wordpress after login?

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.


1 Answers

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)

like image 193
BalusC Avatar answered Sep 20 '22 11:09

BalusC