SESSION ISSUE on withSession method

HI

I’m trying to use session stack with play framework ( version 2.5 ) as reported in official documentation

https://www.playframework.com/documentation/2.5.x/ScalaSessionFlash

but i’ve a issue, in the framework there is not the suggested documentation method “withSession”

Ok(“Hello World!”).withSession( … );

i’ve tryed to use then

Ok(“Hello World!”).session().put(…)
Ok(“Hello World!”).session().get(…)

Methods but they seem to not working propely.

What my fault?

Any suggest?

I’ve just tryed with example reported in :

https://www.playframework.com/documentation/2.5.x/JavaSessionFlash

But i have the same issue, value are not stored in the session, and are returned as null

session(“Product” . “product 1”);

String product = session ( “Product” );

product is set as null value.

Any one have a suggest?

I’m still have the issue.
Nobody have a answer?

Thank you anyway,

I have fixed using play.cache layer .

You are probably seeing a session issue because the session is serialized as a cookie, and that cookie will only be read after a page render. This is referenced in “It’s important to understand that Session and Flash data are not stored in the server but are added to each subsequent HTTP Request, using Cookies.”

The cookie value on the request is immutable and you’ll only see the changed value on subsequent requests. If you send a Redirect(url).addingToSession(key, value) and then the subsequent get will have the session after that.

1 Like