title: How to call a java function from a jsp
body: <p>I require the username used by the user in my project be compared to other usernames already registered. The username should be distinct. For this the input is taken in newuser.jsp which in turn calls a function searchForUsername in SemanticSearch.java. When the new user is registering even the email id is checked for validation and later when the username is typed the above checking needs to be done.
  I have tried one way which is not working.Please point what mistake I am doing?</p>
  
  <p>My code in SemanticSearch.java has constructor:</p>
  
  <pre><code>public SemanticSearch() {}
  </code></pre>
  
  <p>The following code follows after validation of email id.</p>
  
  <p>My code in newuser.jsp is</p>
  
  <pre><code>SemanticSearch myclass=new SemanticSearch();
  
  boolean rets=myclass.searchForUsername(username);
  
  if (rets==false)
  
  {
  
      alert("Username already exists");
  
      document.getElementById("username").value="";
  
      document.getElementById("password").value="";
  
      document.getElementById("username").focus();
  
  }
  </code></pre>
  
  <p>During the click event of adduser button this function has to be called. But during the click function nothing seems to happen. Please help.</p>