title: JSP - Update texarea on button click
body: <p>I am building a JSP webapp using Tomcat and Maven.
  I want to update the value of a textarea in my jsp page when a button on that same jsp page is clicked.</p>
  <p>In my XMLProcessor class I have a function called returnNextMessage() which returns a string of data.</p>
  <p>my jsp:</p>
  <pre><code>&lt;%@ page import=&quot;efidbg.XMLProcessor&quot;%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Home&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;base&quot; class=&quot;&quot;&gt;
  
      &lt;!-- Textbox that i want to fill using java function. --&gt;
      &lt;div id=&quot;u1&quot; class=&quot;ax_default text_area&quot;&gt;
        &lt;textarea id=&quot;u1_input&quot;&gt;&lt;/textarea&gt;
      &lt;/div&gt;
  
  &lt;!-- Button when clicked call returnNextMessage() function --&gt;
      &lt;div id=&quot;u9&quot; class=&quot;ax_default primary_button&quot;&gt;
    &lt;form action=&quot;MyServlet&quot; method=&quot;POST&quot;&gt;
      &lt;input
        type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
    &lt;/form&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I tried to implement it using a servlet called MyServlet but that seems to redirect me to a new page which makes me think that using a servlet is not the correct way to achieve this.</p>
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      String Value = XMLProcessor.returnNextMessage();
      request.setAttribute(&quot;u1_input&quot;, Value);
  }
  </code></pre>
  <p>When I press the submit button I just get redirected to Localhost/MyServlet which gives me an empty page.</p>