title: How to change JSP page content using jQuery AJAX that connects Servlet?
body: <p>I'm new to JSP.
  My problem is, I want to change my JSP page content using AJAX on button click event..
  How can I do it..?</p>
  
  <blockquote>
    <p>This is my 'AjaxTest' JSP file</p>
  </blockquote>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
  
          &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"&gt;&lt;/script&gt;
  
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
  
          &lt;script type="text/javascript"&gt;
              $(document).ready(function () {
                  $('#GetData').click(function () {
  
              &lt;%--
              I want correct codes here,
              that connects to my 'AjaxData' servlet
              and get it's xml content by tags
              and place them in '#PlaceData' paragraph.
              --%&gt;
  
                  });
          &lt;/script&gt;
  
      &lt;/head&gt;
      &lt;body&gt;        
          &lt;button id="GetData" onclick="loadData"&gt;Load&lt;/button&gt;
  
          &lt;p id="PlaceData"&gt;&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <blockquote>
    <p>This is my 'AjaxData' servlet GET method   </p>
  </blockquote>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
              response.setContentType("text/xml");
              response.setCharacterEncoding("UTF-8");
  
              String content = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"
                      + "&lt;person1&gt;"
                      + "&lt;firstname&gt;"
                      + "Indunil"
                      + "&lt;/firstname&gt;"
                      + "&lt;lastname&gt;"
                      + "Girihagama"
                      + "&lt;/lastname&gt;"
                      + "&lt;/person1&gt;";
  
              response.getWriter().write(content);
          }
  </code></pre>
  
  <p>Please tell me correct codes to resolve my problem using jQuery AJAX..</p>