title: Reload current page without losing of user input
body: <p>I create a Login page in which i want to reload my captcha code but i don't want to lose my information entered by the user.</p>
  
  <p>File : <strong>Login.jsp</strong></p>
  
  <pre><code>&lt;body&gt;
  &lt;b&gt;REGISTER&lt;/b&gt;
  &lt;p&gt;Please fill up the form below.&lt;/p&gt;
  &lt;s:form action="register" method="post"&gt;
      &lt;s:textfield label="Enter username" key="userId" maxlength="5" size="30" id="userId"/&gt;
      &lt;s:password label="Enter password" key="userPsw" size="30" /&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;img src="&lt;c:url value='simple-captcha.png' /&gt;" /&gt;
              &lt;br /&gt;
              &lt;p onclick="something()"&gt;Refresh&lt;/p&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;s:textfield label="Enter code" key="captchaResponse" size="30" /&gt;
      &lt;s:submit value="Login" /&gt;
  &lt;/s:form&gt;
  </code></pre>
  
  <p></p>
  
  <p>File : <strong>Javascript code</strong></p>
  
  <pre><code>function something()
  {
      window.location.reload(true);
  }
  
  window.onload = function()
  {
      var a = sessionStorage.getItem('userId');
      if(a !== null) $('#inputName').val(name); 
  
      var b = sessionStorage.getItem('userPsw');
      if(b !== null) $('#userPsw').val(b);
  }
  
  window.onbeforeunload = function() {
      sessionStorage.setItem("userId", $('#userId').val());
      sessionStorage.setItem("userPsw", $('#userPsw').val());
  }
  </code></pre>
  
  <p>On "Refresh" text i want to load my captcha code but i don't want to lose my data.</p>
  
  <p><strong>I refer this link</strong> : <a href="https://stackoverflow.com/questions/17591447/how-to-reload-current-page-without-losing-any-form-data">How to reload current page without losing any form data?</a></p>
  
  <p>but still the query not resolved.</p>