HttpServletRequest: getHeaders(String name) : HttpServletRequest « javax.servlet.http « Java by API






HttpServletRequest: getHeaders(String name)

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HeaderSnoop extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    out.println("Request Headers:");
    Enumeration names = req.getHeaderNames();
    while (names.hasMoreElements()) {
      String name = (String) names.nextElement();
      Enumeration values = req.getHeaders(name); // support multiple values
      if (values != null) {
        while (values.hasMoreElements()) {
          String value = (String) values.nextElement();
          out.println(name + ": " + value);
        }
      }
    }
  }
}

           
       








Related examples in the same category

1.HttpServletRequest: getAuthType()
2.HttpServletRequest: getCookies()
3.HttpServletRequest: getHeader( ) by Accept-Language
4.HttpServletRequest: getHeader( ) by Accept-Charset
5.HttpServletRequest: getRequestURI()
6.ServletRequest: getReader()
7.ServletRequest: getRequestDispatcher(String arg0)
8.HttpServletRequest: getHeaderNames()
9.HttpServletRequest: getPathInfo()
10.HttpServletRequest: getPathTranslated()
11.HttpServletRequest: getQueryString()
12.HttpServletRequest: getRemoteUser()
13.HttpServletRequest: getSession()
14.HttpServletRequest: getUserPrincipal()
15.HttpServletRequest: isRequestedSessionIdFromCookie()
16.HttpServletRequest: isRequestedSessionIdFromURL()
17.HttpServletRequest: isRequestedSessionIdValid()
18.HttpServletRequest: isUserInRole(String arg0)