4.1. Reading Request Headers from Servlets

Reading headers is straightforward; just call the getHeader method of HttpServletRequest, which returns a String if the specified header was supplied on this request, null otherwise. Header names are not case sensitive. So, for example, request.getHeader("Connection") and request.getHeader("connection") are interchangeable.

Although getHeader is the general-purpose way to read incoming headers, there are a couple of headers that are so commonly used that they have special access methods in HttpServletRequest. I'll list them here, and remember that Appendix A (Servlet and JSP Quick Reference) gives a separate syntax summary.

  • getCookies

    The getCookies method returns the contents of the Cookie header, parsed ...

Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.