Take a look at the signatures of the servlet method you're using (probably doGet() or doPost()). You will see that it has parameters HttpServletRequest and HttpServletResponse. Through the HttpServletRequest you can access the values from your form, by using the getParameter() method: if a field in your form has the name "foo", you would call request.getParameter("foo") in the servlet to access it. Note that what you get from the method is a
string, which you have to transform to the correct type. Then you can simply check if it has the expected value.
If the value is wrong, you forward back to the form page, by using the request.getRequestDispatcher().forward() method.
You should also put an error message in the request with request.setAttribute(), to display on the form page so the user knows what's wrong.