Hey there! I'm fairly new to jsp and servlets and I'm trying to figure out how to pass a value to a servlet upon clicking a button. Below is the code snippet that I have been working on. web.xml
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>org.wso2.carbon.identity.application.authentication.endpoint.oauth2.OAuth2Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
test.jsp
function ok() {
$.ajax({
url: "/login",
data: 'test=' +'test',
type: "GET",
async: false,
success: function (data) {
}
});
}
Below is the HTML code in test.jsp
<button id="ok" class="btn btn-primary btn-large" onclick="ok()">OK</button>
The servlet
public class OAuth2Login extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
System.out.print("========do get fires===========");
}
}
However, even though my test.jsp is loading and invoking the doget() of the servlet, it does not do so upon clicking the button. I only want the servlet to be invoked upon the button click, not during the page load. Can anyone help me solve this issue? Apologies for any ignorance on my part. :)