What info can you get from an HttpServletRequest?

Steve Neal Development, Java Programming Leave a Comment

There are many methods on an HttpServletRequest, and if you’re anything like me, you’ll forget exactly what each of them returns. Rather than a long winded investigation into them all, here’s a sample URL:


The ‘/test’ in the URL will map to a servlet called test. The servlet will dispatch the request to a JSP for rendering that has the following scriplet code in it:

RequestURL: <%= request.getRequestURL() %> <br>
RequestURI: <%= request.getRequestURI() %> <br>
QueryString: <%= request.getQueryString() %> <br>
ServletPath: <%= request.getServletPath() %> <br>
PathInfo: <%= request.getPathInfo() %> <br>
PathTranslated: <%= request.getPathTranslated() %><br>
AuthType: <%= request.getAuthType() %> <br>
LocalAddress: <%= request.getLocalAddr() %> <br>
Method: <%= request.getMethod() %> <br>
RemoteUser: <%= request.getRemoteUser() %> <br>

this is the output generated:

RequestURL: https://localhost:8443/test/welcome
RequestURI: /test/welcome
QueryString: a=1&b=2
ServletPath: /test
PathInfo: /welcome
PathTranslated: C:projectstestprojoutartifactstestapp_war_explodedwelcome
Method: GET
RemoteUser: Steve 

Leave a Reply

Your email address will not be published. Required fields are marked *