Determining the HTTP Method
The getMethod() method on the HttpServletRequest returns the HTTP method appearing in the header.
For example, when a client sends the HTTP HEAD request, the server is supposed to treat it like a GET request, but return the headers only—not the data.
The server will automatically discard any data doGet() returns, but (if you had the urge) you could make things a bit more efficient as follows:
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
. . . set headers . . .
if(request.getMethod().equals(“HEAD”)) return ;
. . . return data . . .
}