Hi, the book I'm reading shows the following code to demonstrate the difference between HTTP headers and request properties. I sort of know what HTTP headers are, but I have no idea what request properties are and where each of the properties gets their value from.
I'm guessing many of these request properties come from the HTTP request in which the headers are contained -- from the first part of the HTTP request, before the blank line? If that's the case, do you know which of the request properties come directly from the HTTP request and which are determined in other ways by the server? (I guess what's really bugging me is where do each of the request properties come from? For example, the scheme, protocol, etc...is that information in the HTTP request, determined some other way, etc...)
Also, what's the difference between the following similar request properties:
- contextPath, servletPath, requestURI, requestURL
- serverName, remoteAddr, remoteHost (why does the first one say localhost while the other two say 127.0.0.1?)
If you could explain what request properties are and the difference between them and HTTP headers, I'd really appreciate it. Thanks.
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Request Info</title>
</head>
<body bgcolor="white">
The following information was received:
<ul>
<li>Request Method:
<c:out value="${pageContext.request.method}" />
<li>Request Protocol:
<c:out value="${pageContext.request.protocol}" />
<li>Context Path:
<c:out value="${pageContext.request.contextPath}" />
<li>Servlet Path:
<c:out value="${pageContext.request.servletPath}" />
<li>Request URI:
<c:out value="${pageContext.request.requestURI}" />
<li>Request URL:
<c:out value="${pageContext.request.requestURL}" />
<li>Server Name:
<c:out value="${pageContext.request.serverName}" />
<li>Server Port:
<c:out value="${pageContext.request.serverPort}" />
<li>Remote Address:
<c:out value="${pageContext.request.remoteAddr}" />
<li>Remote Host:
<c:out value="${pageContext.request.remoteHost}" />
<li>Secure:
<c:out value="${pageContext.request.secure}" />
<li>Cookies:<br>
<c:forEach items="${pageContext.request.cookies}" var="c">
��<b><c:out value="${c.name}" /></b>:
<c:out value="${c.value}" /><br>
</c:forEach>
<li>Headers:<br>
<c:forEach items="${headerValues}" var="h">
��<b><c:out value="${h.key}" /></b>:
<c:forEach items="${h.value}" var="value">
<br>
����<c:out value="${value}" />
</c:forEach>
<br>
</c:forEach>
</ul>
</body>
</html>