Knowledgebase: Java/JSP Hosting Plans
Processing a HEAD Request in a Servlet
Posted by Customer Service on 25 May 2005 12:49 AM
By default, a HEAD request is automatically processed by the HttpServlet.doGet() method using a modified response object that simply counts and discards any characters written to the buffer. If it is necessary to improve the performance of a servlet that is frequently accessed with a HEAD request method, you can override the HttServlet.doHead() method and implement a more efficient algorithm. Typically, a doHead() implementation sets the content length and type, as demonstrated by this example.

Note: In the JWSDP 1.0, calling resetBuffer() does nothing in a HEAD request. Therefore, if resetBuffer() is used during servlet processing, a GET and HEAD request may return different content lengths.

    // This method is called by the servlet container to process a HEAD request.
    // There may be many threads calling this method simultaneously.
    public void doHead(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        // Set the content length and type
(552 vote(s))
Not helpful

Comments (0)