2 Minutes To Code (β Version)

Java Servlets - 2 minute tutorial

How to get headers sent by http client from HttpServletRequest

The http clients sends headers along with the http request and you can get these from the HttpServletRequest by using the method String getHeader(String).

To get a multi-valued header, use the method Enumeration<String> getHeaders(String).

To get the names of all headers, use the method Enumeration<String> getHeaderNames().

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
	String language = req.getHeader("lang");
	Enumeration<String> acceptList = req.getHeaders("Accept");
	
	Enumeration<String> headerNames = req.getHeaderNames();
}