title: Passing a value from servlet doGet() to javascript's $.get() returning whole HTML instead
body: <p>My work necessitates working with Java logic and Javascript. So, now I am trying to pass a value to javascript once a doGet() of a servlet is executed. Somehow, instead of some Java string, javascript displays the whole HTML String as the value (<code>"&lt;html&gt;...&lt;body&gt;....&lt;/body&gt;...&lt;/html&gt;"</code>).</p>
  
  <p>The following is an excerpt from the <b>hello.jsp</b>:</p>
  
  <pre><code>&lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      $.get('hello', function(data) {
          $('#data').text(data);
      });
  &lt;/script&gt;
  
  &lt;body&gt;
  &lt;div id="input"&gt;
      &lt;form action="hello" method="get"&gt;
      &lt;p&gt;&lt;input type="text" name="query" value="${messages.query}"&gt;&lt;input type="submit" value="Go!"&gt;&lt;/p&gt;
      &lt;hr&gt;
      &lt;/form&gt;
  
  &lt;/div&gt;
  
  &lt;div id="data"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Except from <b>HelloController.java</b>:</p>
  
  <pre><code>@WebServlet("/hello")
  public class HelloServlet extends HttpServlet {
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  
          String data = "Hello World from doGet()!";
          response.setContentType("text/plain");
          response.setCharacterEncoding("UTF-8");
          response.getWriter().write(data);
  
          request.getRequestDispatcher("/WEB-INF/pages/hello.jsp").forward(request, response);
      }
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  /* 
  ...
  */
      }
  
  }
  </code></pre>
  
  <p>So, once doGet() is executed, I want <code>"Hello World from doGet()"</code> to be passed back as <code>data</code> to javascript's <code>$.get()</code>, but instead <code>"&lt;html&gt;...&lt;body&gt;....&lt;/body&gt;...&lt;/html&gt;"</code> is displayed in the <code>data</code> div. Any advice? </p>