Play Framework HTML SCALA VIEW Sessions


Can someone tell me which documentation i should read or use (about play framework) to :

Not allowed a user (A) to open an HTML (view page ex index.scala.html) if it is already opened from another user (B) This means that my configured page will be showed only for one user in same time, if this is user close the HTML page then someone else can open it …

Thank you so much

cookie-based http sessions are unique per user/user-agent so it won’t work to use as a lock.

in order to do page-level locking you’ll need some shared lock that multiple users/requests can access…
that could be

  • a singleton object in your application (like managed by Guice or stored in the application context)
  • a row-level record in a database
  • an entry in a shared cache

that’s up to you.

to have a mutually exclusive html page, you could write a PageLockAction on your page handler method.

controller method

public Result page(Request request) {
  return ok(view.html.YourPage.render());


public class PageLockAction extends Simple.Action {

  private final PageLock lock;

  public PageLockAction(PageLock lock) {
    this.lock = lock;

  public CompletionStage<Result> call(Request request) {
    // double-checked lock read
    // if available, acquire lock
    //   return delegate.apply(request);
    // else
    //   return not available page

you’d then need to have an endpoint to release the lock… so your page would probably need to make an api call to that endpoint when the user A is done to release the lock… otherwise user B would never be able to access the page again.

1 Like


Thank you for your return and codes, i will check soon as possible then giving you my feed back, Thank you again and again :slight_smile:

1 Like