title: javascript and jsp
body: <p>when i try to access a jsp variable in javascript i always get it as null. why is this so? how do i get actual jsp variable value in javascript. here is my code </p>
  
  <pre><code>&lt;%! String oldpassword; %&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;script type="text/javascript"&gt;
          function redirect()
          {
          var oldpassword_actual="&lt;%= oldpassword %&gt;";
          var oldpassword_entered=document.form.oldpassword.value;
          var newpassword=document.form.newpassword.value;
          var reenterpassword=document.form.confirmpassword.value;
  
          alert(oldpassword_actual);
          alert(oldpassword_entered);
          alert(newpassword);
          alert(reenterpassword);
          return false;
          }
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body align="center"&gt;
      &lt;form name="form" action="" method="post"&gt;
              Enter old password&lt;input type="password" name="oldpassword"&gt;&lt;/br&gt;&lt;/br&gt;
              Enter new password&lt;input type="password" name="newpassword"&gt;&lt;/br&gt;&lt;/br&gt;
              Reenter new password&lt;input type="password" name="confirmpassword"&gt;&lt;/br&gt;&lt;/br&gt;
          &lt;%
          oldpassword=(String)session.getAttribute("Password");
          %&gt;
              &lt;input type="submit" name="confirm" value="Confirm" onclick="return redirect()"&gt; 
      &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>when the alert box pops up..it gives a null value for the jsp variable..</p>