title: Java equivalent of session_start(), session_destroy(), and $_SESSION['username']
body: <p>In PHP when a user logs into her account, I do the following in order to remember the user as she navigates through the site:</p>
  
  <pre><code>session_start();
  ...
  $_SESSION['username'] = $username;
  </code></pre>
  
  <p>On any other page that may require sensitive data, I check that <code>$_SESSION['username']</code> is valid.</p>
  
  <p>When a use logs out, I do the following</p>
  
  <pre><code>unset($_SESSION['username']
  session_destroy();
  </code></pre>
  
  <p>How do I do the same thing in Java? I have a REST API which uses <code>Jersey</code> and <code>EJB</code>. In case the following is important, I am persisting with JPA, Hibernate, Glassfish, and mysql.</p>
  
  <p>UPDATED FOR VERIFICATON:</p>
  
  <p>Is this correct?</p>
  
  <pre><code>@Path("login")
  public class UserLoginResource {
  
    @EJB
    private LoginDao  loginDao;
  
    @Context
    HttpServletRequest request;
  
    @POST
    public Response login(JAXBElement&lt;Login&gt; jaxbLogin){
      Login login = jaxbLogin.getValue();
      loginDao.authenticateUserLogin(login);
      HttpSession session = request.getSession();
      session.setAttribute("username", login.getUsername());
      return Response.ok().build();
    }
  }
  </code></pre>