title: Action class getting null value from jsp page through ajax call
body: <p>How can I get the JSP value from action class through Ajax? When I enter the username want to check to database the username is present or not. For that purpose, I am using Ajax.</p>
  
  <p>Here my JSP code:</p>
  
  <pre><code> $(document).ready(function(){
                  $("#username").change(function(){
                      $("#message").html("checking...");          
                              $("#message").css('color', 'red');
  
                      var username=$("#username").val();
                      alert(username);
  
                      $.ajax({
                          type:"post",
                          url:"CheckUserAction",
                          data:"username="+username,
                          success:function(data){                        
  
  
  //checking the code for username is present in database or not
                             }
          });
      });
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;%@include file="index.html" %&gt;
   &lt;div class="box2"&gt;
      &lt;center&gt;
      &lt;!-- &lt;div class="header"&gt;&lt;/div&gt; --&gt;
      &lt;center&gt;
          &lt;div class="outer"&gt;&lt;center&gt;
          &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
          &lt;div class="inner"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
          &lt;center&gt; 
              &lt;s:form action="RegisterationProcess" id="loginForm"  name="loginForm" method="post" &gt;
                  &lt;table width="auto" border="0" align="center" cellpadding="2" cellspacing="0" class="tab"&gt;
  
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;&lt;center&gt;&lt;b&gt;Registration Form&lt;/b&gt;&lt;/center&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;&lt;hr&gt;&lt;/td&gt;
                  &lt;/tr&gt; 
  
                  &lt;input type="hidden" name="register" value="register"/&gt;      
                  &lt;tr&gt;     
                      &lt;td&gt;&lt;s:textfield name="user.userName"class="textfield" id="login" label="Name"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;  
                      &lt;td&gt;&lt;s:textfield name="user.userId" id="username"  class="textfield" label="User Name" /&gt; &lt;/td&gt; 
                      &lt;div id="message"&gt;&lt;/div&gt;        
                  &lt;/tr&gt;`enter code here`
  
                  &lt;tr&gt;  
                      &lt;td&gt;&lt;s:password name="user.password"  class="textfield" id="password" label="Password" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt;&lt;s:textfield name="user.emailId" class="textfield" id="emailAddress" label="Email" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input id="sbmt" type="submit" value="Register"&gt;&lt;/td&gt;
                  &lt;!-- &lt;td&gt;&lt;s:submit value="Register"  id="sbmt"/&gt;&lt;/td&gt; --&gt;
                  &lt;/tr&gt;
  </code></pre>
  
  <p>and this is my <code>CheckUserAction</code> class:</p>
  
  <pre><code>      private String userId;
      private String userName;
  
    public UserImpl getUser()
      {
          return user;
      }
  
  public void setUser(UserImpl user) 
  {
      this.user = user;
  }
  
  
  public String getUserName() 
  {
      return userName;
  }
  
  public void setUserName(String userName) 
  {
      this.userName = userName;
  }
  
  public String getUserId()
  {
      return userId;
  }
  
  public void setUserId(String userId) 
  {
      this.userId = userId;
  }
  
  public String execute()
  {
    System.out.println("username"+userName);
  }
  }
  </code></pre>
  
  <p>I am getting username as <code>null</code>.</p>