在jsp页面中获取http请求头的代码(转)

转自:http://www.ericgiguere.com/tools/http-header-viewer.html

Header Viewer Source Code

In case you're wondering, here is the code that prints the headers:

<table width="100%" border="0" cellspacing="0"

       cellpadding="8" bgcolor="#EEEEEE">

      

    <tr><td><b>Name</b></td><td><b>Value</b></td></tr>

    <tr><td colspan="2" width="100%" height="2" bgcolor="#000000"></td></tr>

   

    <c:forEach var="hname" items="${pageContext.request.headerNames}">

   

        <c:forEach var="hvalue" items="${headerValues[hname]}">

            <tr><td valign="top"><c:out value="${hname}"/></td>

            <td valign="top"><c:out value="${hvalue}"/></td></tr>

            <tr><td colspan="2" bgcolor="#000000" width="100%" height="1"></td></tr>

   

        </c:forEach>

    </c:forEach>

</table>

 

As you can see, it's very easy to access the HTTP headers using the Java Standard Tag Library (JSTL), a powerful tag library for use with JavaServer Pages (JSP).

If you didn't realize that this page was built using JSP pages, See How This Site Works for the details.