简体   繁体   中英

How can I set session in action composition in Play framework using Java

I have following code that should set a redirect url to session , but it doesn't do that.

public class WithUserActionAnnotation extends Action<WithUserAction> {

    public F.Promise<Result> call(Http.Context ctx) throws Throwable {
        User user = (User) ctx.args.get(SecureSocial.USER_KEY);

        if (user != null) {
            return delegate.call(ctx);
        } else {
            Result redirect = Results.redirect(routes.LoginPage.login());
            redirect.session().put(SecureSocial.ORIGINAL_URL, ctx.request().uri());
            return F.Promise.pure(redirect);
        }
    }
}
 ctx._requestHeader().session().get("AUTH");

The following works for me

Http.Session session = Http.Context.current().session();
session.put(SecureSocial.ORIGINAL_URL, ctx.request().uri());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM