title: How to typecast object to int in jsp
body: <p>I need to be able to compare the value that is in an object to an int, but I can't seem to get the typecasting working.  I have tried all the methods described here: <a href="https://stackoverflow.com/questions/6031278/session-attribute-access-and-converting-to-int">Session attribute access and converting to int?</a> but they all give me a null pointer exception.  Here is the code I have that's not working.</p>
  
  <p>Here is the code that puts values into the session.</p>
  
  <pre><code>&lt;script&gt;sessionStorage.clickcount=1;&lt;/script&gt;
  &lt;input type ="hidden" name="ttmp" value="222" id="ttmp" /&gt;
  &lt;script&gt;document.getElementById('ttmp').value = sessionStorage.clickcount;&lt;/script&gt;
  </code></pre>
  
  <p>This was tried with the input line before and after the script.</p>
  
  <pre><code>&lt;%
    String value = request.getParameter("ttmp");
    if (value != null) {
      session.setAttribute("test", value);
    }
    Integer userid = Integer.parseInt(session.getAttribute("test").toString());
    ...
    if (userid == 1) {
    ...
    }
  %&gt;
  </code></pre>