title: Why do variables not retain their values in Servlets in spite of being shared during multithreading
body: <p>I have a simple JSP page that has a form taking value of parameter <code>val</code></p>
  
  <pre><code>&lt;form action="test"&gt;
  Insert Value&lt;input type="text" name="val"/&gt;
  &lt;input type="submit"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><br>Next I have a servlet <code>test.java</code> which takes <code>val</code> and prints it. The servlets <code>doGet</code> method looks like this-<br></p>
  
  <pre><code>        String val=request.getParameter("val");
          response.setContentType("text/html");
          PrintWriter p=response.getWriter();
          p.println("Value of parameter is "+val);
  </code></pre>
  
  <p><br>
  Now, I've read that during initialization only one instance of servlet is created i.e. only one object of servlet is created and multiple requests are handled using Multiple Threads.<br><br>
  Now, since only one instance of servlet is created therefore only one instance of variable <code>val</code> must have been created which can hold just one value at a time, then why is it that during multiple requests each user can access its own value of <code>val</code> ?<br>Shouldn't the value of <code>val</code> be shared among multiple requests and reflect its change in corresponding requests ?<br>Please Help. Thanks.</p>