How do I prevent my form from submitting if one of the fields is blank (JSP)?

Below is my JSP file, and I was using a servlet to check if the fields are null, but apparently this needs to be done on the client side. How do I prevent the form from submitting when the submit button is pressed and a field is empty?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ page session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
h1 { font-family : cooper black;}
<title>Add a Phonebook Entry</title></head>
<h1> Add a Phonebook Entry</h1>
<form action="" method="GET">
<table summary="phonebook entry table">
        <td>Last name:</td>

        String last = "";
        String first = "";
        String phone = "";

            last = (String) request.getParameter("surname");
            first = (String) request.getParameter("firstname");

            phone = (String) request.getParameter("phone");

        <td><input type="text" title="enter your last name here" name="surname" name="initials" size=10 maxlength=10 value=<%= last %> ></td>
        <td>First name:</td>
        <td><input type="text" name="firstname" size=10 maxlength=10 value=<%=first %> ></td>
        <td>Phone number: </td>
        <td><input type="text" name="phone" maxlength=10 size=10 value=<%=phone %> > </td>
<br><input type="submit" value="Submit">
<p> View the phonebook <a href="./Display.jsp">here</a></p>



Basically have a short script which checks all inputs are populated. If not then block the submission request.

You will still have to implement something server side to check the fields, as a user could disable JavaScript. The same goes for my following suggestion.


There's also the HTML5 required attribute. I don't think this is supported in all browsers yet.

<input type="text" name="username" required>

If not populated and HTML5 validation is enabled the form will not submit.

Need Your Help

Test for throwing Errors in Ember.js

ember.js qunit ember-qunit

Using the integrated QUnit testing framweork I need to test wether or not visiting a route causes an Error to be thrown.

iOS: Issues with sending unicode text on server

ipad unicode utf-8 ios5.1 unicode-string

I have come across really frustrating issue related to Unicode text and I am not able to do anything more to fix it. I am using following code to store English and Japanese texts on server from iPa...