title: Unable to retrieve value set in servlet
body: <p>I have, what I believe, is an extremely simple problem, yet all of my attempts to resolve it have failed.</p>
  
  <p>In a nutshell:
   I have a JSP file with a form that invokes a Java Servlet.
   The servlet processes the input and returns a variable (attribute) and redirects back to the <strong>same</strong> jsp.
   I want to the jsp to process the returned attribute using <strong>JavaScript</strong>, NOT a scriptlet.</p>
  
  <p>JSP Code (test.jsp):</p>
  
  <pre><code>&lt;html&gt;
    ...
    &lt;%@page language="java"
      import="java.sql.*" 
      import="java.util.*"
    %&gt;
    ...
    &lt;body&gt;
      &lt;script type='text/javascript'&gt;
        var name = session.getAttribute("test");
        alert(name);
      &lt;/script&gt;
      ...
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And the Servlet code:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) {
    request.getSession().setAttribute("test", "value");
    String redirectedPage = "/test.jsp";
    RequestDispatcher reqDispatcher = getServletConfig().getServletContext().getRequestDispatcher(redirectedPage);
    reqDispatcher.forward(request,response);
  }
  </code></pre>
  
  <p>I believe that the problem stems from my declaration of the session variable:</p>
  
  <pre><code>var name = session.getAttribute("test");
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>var name = (String) session.getAttribute("bob");
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>String name = (String) session.getAttribute("bob");
  </code></pre>
  
  <p>I can access this attribute from within my form using a scriptlet (&lt;% %>), but that doesn't allow me to modify/process the returned attribute, which I need to do.</p>
  
  <p>Any help is greatly appreciated.  If you feel this question has already been asked/addressed (I've searched), please POLITELY let me know.</p>