title: HTML+Ajax+servlet not working
body: <p>hi im trying out a servlet based ajax  here in my program im using a html page with button and textbox when i click the button it should fire some ajax request to the server done some computations and return result in the same page</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
  
  
      &lt;/head&gt;
      &lt;body&gt;
         &lt;h3&gt;Ajax in servlets&lt;/h3&gt;
  
          &lt;div id="change"&gt; hi there&lt;/div&gt;
          &lt;input type="text" id="fname" name="solo"&gt;
          &lt;input type="button" align="center" value="Ajax" onclick="ajaxreq()" /&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>in this html page a text box and a button when i click on the button it should execute the following java script function</p>
  
  <pre><code> var xmlreq=null;
              var a=document.getElementById("fname");
              function ajaxreq(){
  
  
                  if(window.XMLHttpRequest){
                      xmlreq=new XMLHttpRequest();
  
                  }
                      else if(window.ActiveXObject){
                          xmlreq=new ActiveXObject("Microsoft.XMLHTTP");
                      }
                      try{
                    xmlreq.onreadystatechange=response;
                       xmlreq.open("GET","Servlethello?an=+a",true);
                          xmlreq.send();
  
          }
                      catch(e){
  
                          alert("some error")
                      }
      }
  function response(){
  var res=xmlreq.responseText;
  document.write(res);
  alert(res);
  document.getElementById("change").innerHTML=res;
  
                    }
  
  
  
  
  
  
  
  
          &lt;/script&gt;
    here i have created a ajax call and send the request to the servlet Servlethello
  
  
  
  public class Servlethello extends HttpServlet {
      @Override
  public void doGet(HttpServletRequest req,
                       HttpServletResponse res)throws ServletException, IOException {
  res.setContentType("text/html");
    PrintWriter out = res.getWriter();
  out.println("&lt;h1&gt;");
  String a=req.getParameter(an);
  out.println("solorules"+a);
  out.println("&lt;/h1&gt;");
  out.close();
  
  
  }
  
  
      }
  </code></pre>
  
  <p>the variable a fetches the value entered in the textbox and send it to the servlet
   xmlreq.open("GET","Servlethello?an=+a",true); to this servlet</p>
  
  <pre><code>public void doGet(HttpServletRequest req,
                       HttpServletResponse res)throws ServletException, IOException {
  res.setContentType("text/html");
    PrintWriter out = res.getWriter();
  out.println("&lt;h1&gt;");
  String a=req.getParameter(an);
  out.println("solorules"+a);
  out.println("&lt;/h1&gt;");
  </code></pre>
  
  <p>and this servlet should be displayed here
      hi there using this java script </p>
  
  <pre><code>var res=xmlreq.responseText;
      document.write(res);
      alert(res);
      document.getElementById("change").innerHTML=res;
  </code></pre>