I have this jsp page –
<%@page import="java.text.Normalizer.Form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<legend>Create new customer</legend>
<%!
boolean checkForm(Form theForm)
{
// some checks on "theForm" ..
return false ;
}
%>
<form action="CreateCustomerServlet" method="GET" onsubmit=<%=checkForm() %>>
// form's fields ..
<input type="submit" value="Create customer" />
</form>
</fieldset>
</body>
</html>
What I trying to do is when press on submit it will go to the checkForm function and check the form , and only if checkForm returned true it will go CreateCustomerServlet servlet .
But when I run on server this page and press on submit button I see that it’s ignore from thecheckForm and directly go to CreateCustomerServlet servlet .
I know that to this with javascript is very easy .. but I want to do it with java function .
When the JSP is evaluated, it produces a static HTML page that’s returned to the user. The server won’t be involved in the process again until it receives the form submission. If you do want some server-side behavior executed from the
onsubmithandler, you’ll need to do it via AJAX.