title: Calling Java function within Javascript in JSP application
body: <p>I would like to access a variable and a set of functions from within a javascript segment. I have two files:</p>
  
  <p><strong>testJSP.jsp</strong></p>
  
  <pre><code>&lt;%@page import="test.tester"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;%
              String thing = "Exciting String";
              tester testy = new tester(thing);
          %&gt;
          &lt;input type="submit" onclick="test()" value="Sample Text" /&gt;
          &lt;div id="testDiv" &gt;Boring String&lt;/div&gt;
          &lt;script language="javascript" &gt;
              funciton test() {
                  document.getElementById("testDiv").innerHTML = &lt;%=testy.getString()%&gt;;
              }
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>tester.java</strong></p>
  
  <pre><code>package test;
  
  public class tester {
      private String privy;
  
      public tester(String testString) {
          privy = testString;
      }
  
      public String getString() {
          return "new " + privy;
      }
  }
  </code></pre>
  
  <p>Essentially, when the button is clicked, I want the element with id "testDiv" to be changed according to the function in the java file. I may be overlooking a very simple method, or perhaps there is a far more complex way of approaching this seemingly simple problem. </p>