title: How to show value from database to jsp without refreshing the page using ajax
body: <p>I am an Ajax fresher</p>
  
  <p><strong>Ajax</strong></p>
  
  <pre><code>function ajaxFunction() {
    if(xmlhttp) { 
     var txtname = document.getElementById("txtname");
      xmlhttp.open("POST","Namelist",true);
  
      xmlhttp.onreadystatechange  = handleServerResponse;
      xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      xmlhttp.send("txtname=" + txtname.value); 
    }
  }
  
  function handleServerResponse() {
     if (xmlhttp.readyState == 4) {
       if(xmlhttp.status == 200) {
         document.getElementById("message").innerHTML=xmlhttp.responseText;
       }
       else {
          alert("Error during AJAX call. Please try again");
       }
     }
  }
  </code></pre>
  
  <p><strong>jsp</strong></p>
  
  <pre><code>&lt;form name="fname" action="Namellist" method="post"&gt;
  
      Select Category :
      &lt;select name="txtname" id="txtname"&gt;
       &lt;option value="Hindu"&gt;Hindu&lt;/option&gt;
       &lt;option value="Muslim"&gt;Muslim&lt;/option&gt;
       &lt;option value="Christian"&gt;Christian&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type="button" value="Show" id="sh" onclick="ajaxFunction();"&gt;
      &lt;div id="message"&gt;here i want to display name&lt;/div&gt;&lt;div id="message1"&gt;here i want to display meaning&lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p><strong>servlet</strong></p>
  
  <pre><code>String ct=null;  
  ct=request.getParameter("txtname");
        Connection con=null;
        ResultSet rs=null;
        Statement st=null;
  try{
  con=Dbconnection.getConnection();
  PreparedStatement ps=con.prepareStatement("select name meaning from (select * from namelist order by dbms_random.value)where rownum&lt;=20 and category='+ct+'" );
  rs=ps.executeQuery();
  
   out.println("name" + rs);
   **Here I have confusion,**
  
  }
  catch(Exception e)
  {
      System.out.println(e);
  }
  </code></pre>
  
  <p>How can i diaplay servlet value to jsp.
  Please help me? or please provide some good tutorial links.</p>