Thursday, October 2, 2008

Reading Request Information

When an HTTP client such as web browser sends a request to a wen server, along with the request it also sends some HTTP variables like Remote address, Remote host, Content type etc. In some cases these variables are useful to the programmers. So here is the code of the jsp file which prints the HTTP request information:

<%@page contentType="text/html" import="java.util.*" %>

Request Information:

Request Method: <%=request.getMethod()%>
Request URI: <%=request.getRequestURI()%>
Request Protocol: <%=request.getProtocol()%>
Path Info: <%=request.getPathInfo()%>
Path translated: <%=request.getPathTranslated()%>
Query String: <%=request.getQueryString()%>
Content length: <%=request.getContentLength()%>
Content type: <%=request.getContentType()%>
Server name: <%=request.getServerName()%>
Server port: <%=request.getServerPort()%>
Remote user: <%=request.getRemoteUser()%>
Remote address: <%=request.getRemoteAddr()%>
Remote host: <%=request.getRemoteHost()%>
Authorization scheme: <%=request.getAuthType()%>