title: PrintWriter output to jsp page inside body tag
body: <p>This is the code to print to my jsp page. However I have other code in the page. When I call this function I want it to print the message right after where it is called. I can't check for sure because I am using xhtml negotiation, but I suspect it prints after the /html tag.</p>
  
  <p>This is my function</p>
  
  <pre><code>public Print(HttpServletRequest request,HttpServletResponse response){
          try{
              response.setContentType("text/html");
              PrintWriter out = response.getWriter();
              out.print("&lt;p&gt;haha&lt;/p&gt;");
          }catch(IOException e){
              e.printStackTrace();
          }
      }
  };
  </code></pre>
  
  <p>This is where I call it</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Register&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;%@ page import="com.otrocol.app.*" %&gt;
  &lt;%
      Print(request, response);
  %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is what I think the result is:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Register&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  "haha"
  </code></pre>
  
  <p>This is what I want the response to be:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
      &lt;head&gt;
          &lt;title&gt;Register&lt;/title&gt;
      &lt;/head&gt;  
      &lt;body&gt;
       "haha"
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>This is the error I get:</p>
  
  <p><img src="https://i.stack.imgur.com/QusU0.png" alt="enter image description here"></p>