title: Passing value from a jsp button click to a servlet
body: <p>ininI am bit new to jsp and servlet. I need to pass a value to a servlet on a button click. below I have mentioned my code.
  web.xml</p>
  
  <pre><code>&lt;servlet&gt;
  &lt;servlet-name&gt;Login&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.wso2.carbon.identity.application.authentication.endpoint.oauth2.OAuth2Login&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Login&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/login&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>test.jsp</p>
  
  <pre><code>       function ok() {
          $.ajax({
              url: "/login",
              data: 'test=' +'test',
              type: "GET",
              async: false,
              success: function (data) {
  
              }
          });
      }
  </code></pre>
  
  <p>below is my html code in test.jsp</p>
  
  <pre><code>&lt;button id="ok" class="btn btn-primary btn-large" onclick="ok()"&gt;OK&lt;/button&gt;
  </code></pre>
  
  <p>The servelet</p>
  
  <pre><code>public class OAuth2Login extends HttpServlet {
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
          IOException {
         System.out.print("========do get fires===========");
      }
  </code></pre>
  
  <p>}</p>
  
  <p>But when my test.jsp is loading it invokes the doget() of the servlet. But at the button click it does not. I dont need to invoke the servlet at the page load. But I need it on the button click. Help me to solve this out. Sorry for the ignorance. :)</p>