title: servlet not forwarding session attribute to jsp
body: <p>Using embedded tomcat, this code works:</p>
  
  <p><strong>Servlet</strong>:</p>
  
  <pre><code>String test = "test";
  request.setAttribute("test", test);
  request.getRequestDispatcher("/index.jsp").forward(request, response);
  </code></pre>
  
  <p><strong>JSP</strong>:</p>
  
  <pre><code>&lt;%= request.getAttribute("test") %&gt;
  </code></pre>
  
  <p>It sets the attribute <code>test</code> and then prints it out on the servlet <code>/example</code>'s jsp page <code>example.jsp</code>.</p>
  
  <hr/>
  
  <p>However, if I try to set the attribute within the session then I don't get the same result, instead, I get a <code>null</code> when using this:</p>
  
  <p><strong>Servlet</strong>:</p>
  
  <pre><code>String test = "test";
  request.getSession().setAttribute("test", test);
  request.getRequestDispatcher("/index.jsp").forward(request, response);
  </code></pre>
  
  <p><strong>JSP</strong>:</p>
  
  <pre><code>&lt;%= session.getAttribute("test") %&gt;
  </code></pre>