title: Java servlet and JSP accessing the same session bean
body: <p>Let's say I have a simple Login servlet that checks the passed <code>name</code> and creates <code>User</code> object and stores it in a session.</p>
  
  <pre><code>User user = new User();
  user.setId(name);
  
  request.getSession().setAttribute("user", user);
  response.sendRedirect("index.jsp");
  </code></pre>
  
  <p>In the <code>index.jsp</code> page I access the user object through <code>jsp:useBean</code></p>
  
  <pre><code>&lt;jsp:useBean id="user" scope="session"
               class="package.name.User"/&gt;
  
  &lt;div class="panel"&gt;
      Welcome ${user.id}
  &lt;/div&gt;
  </code></pre>
  
  <p>It works so far. </p>
  
  <p>From the jsp beans documentation</p>
  
  <blockquote>
    <p>To locate or instantiate the Bean,
     takes the following
    steps, in this order:</p>
    
    <ol>
    <li>Attempts to locate a Bean with the scope and name you specify.</li>
    <li>Defines an object reference variable with the name you specify.</li>
    <li>If it finds the Bean, stores a reference to it in the variable. If
    you specified type, gives the Bean
    that type.</li>
    <li>If it does not find the Bean, instantiates it from the class you
    specify, storing a reference to it in
    the new variable. If the class name
    represents a serialized template, the
    Bean is instantiated by
    java.beans.Beans.instantiate.</li>
    <li>If  has instantiated (rather than located) the Bean, and if
    it has body tags or elements (between
     and ),
    executes the body tags.</li>
    </ol>
  </blockquote>
  
  <p><strong>The questions:</strong>   </p>
  
  <blockquote>
    <p>Attempts to locate a Bean with the scope and name you specify </p>
  </blockquote>
  
  <p>It does not specify the "locate" process. Does it mean it will check <code>HttpServletRequest.getSession()</code> or just check whether other pages already created this bean or not?</p>
  
  <blockquote>
    <p>If it does not find the Bean, instantiates it from the class you specify, storing a > reference to it in the new variable.</p>
  </blockquote>
  
  <p>This actually means that Jsp can associate a newly created bean with session using <strong>jsp_internal_name_user</strong>.
  There is no word about how Jsp stores and finds beans in the session.</p>
  
  <p>There is an option to access session objects by using <code>${sessionScope.user}</code> and that will guarantee that "user" from the Java session object will be get. The same one I put into by myself.   </p>
  
  <p>Java EE 5 example "Book Store" access session objects using <code>${sessionScope.name}</code> approach. </p>
  
  <p>Using just <code>${user}</code> works. And this is what worries me. I would like to see a specific sentence in the specification about the <code>locate</code> process and whether <code>${user}</code> must work or whether it is up to the JSP and/or JSTL reference implementation.</p>