title: Get data from servlet to JSP without forward?
body: <p>I need a double value from my servlet to markup in my JSP. My doGet() is sending back formatted HTML tables with values from an ArrayList, so after I got that working I decided to tackle this part.</p>
  
  <p>Servlet: </p>
  
  <p>//Code getting the tables I need</p>
  
  <pre><code>    //Send back the result, this all works good
      response.setContentType("text/html");
      response.setCharacterEncoding("UTF-8");
      response.getWriter().write(returnAsHTML.toString());
  </code></pre>
  
  <p>What I added to try and get the double value</p>
  
  <pre><code>    //Send back the result
  
      double test = 20;
      request.setAttribute("Test",test);
  
      response.setContentType("text/html");
      response.setCharacterEncoding("UTF-8");
      response.getWriter().write(returnAsHTML.toString());
  
      getServletContext().getRequestDispatcher("index.jsp").forward(request,response);
  </code></pre>
  
  <p>In JSP:</p>
  
  <pre><code>  &lt;!-- This variable is unresolved --&gt;
    &lt;small&gt;Test : ${Test}&lt;/small&gt;
  </code></pre>
  
  <p>The forwarding seems to crash the whole party. I am new to JSP, I'm sure I am missing something small. I need to keep the response.getWriter() stuff there, it gets a lot of the information I need. Now I just don't know how to get my double values I need as well, because they will be displayed on a whole different part of the page.</p>