title: JSP - how to pass a javascript var in session.setAttribute?
body: <p>New to learning JSP, and trying out passing data between two pages.</p>
  
  <p>I'm wondering if it is possible to pass a javascript variable to <code>session.setAttribute()</code> </p>
  
  <p>At the moment, I can pass a string of text through 2 jsp files like so:</p>
  
  <p>JSP1:</p>
  
  <pre><code>&lt;% String text = "hello";
  session.setAttribute("test", text);%&gt;
  </code></pre>
  
  <p>JSP2:</p>
  
  <pre><code>var someText = "&lt;%=session.getAttribute("test")%&gt;"
  </code></pre>
  
  <p>which works fine.</p>
  
  <p>However, is it possible to pass through a <code>var</code> into <code>session.setAttribute</code> instead? I store some data in a javascript variable and would like to send it across to the second JSP file.</p>
  
  <p>So for example:</p>
  
  <pre><code>var number = 7;
  &lt;%session.setAttribute("test", number);%&gt;
  </code></pre>
  
  <p>I've tried this out and I get the error "number cannot be resolved to a variable"</p>
  
  <p>Thanks!</p>