HTTP servlet request url components 

Joined:
04/19/2010
Posts:
94

July 26, 2010 15:55:41    Last update: March 28, 2012 15:28:02
Given the URL:
http://www.mydomain.com/myWebApp/theServlet/p1/p2/p3;sid=123?param=abc

This would be the output of the various method calls on HttpServletRequest:
String scheme = request.getScheme();           // http
String serverName = request.getServerName();   // www.mydomain.com
int portNumber = request.getServerPort();      // default 80
String contextPath = request.getContextPath(); // /myWebApp
String servletPath = request.getServletPath(); // /theServlet
String pathInfo = request.getPathInfo();       // /p1/p2/p3;sid=123
String requestURI = request.getRequestURI();       // /myWebApp/theServlet/p1/p2/p3;sid=123
String queryString = request.getQueryString(); // param=abc
boolean isSecure = request.isSecure();         // false, would be true if protocol is HTTPS
Share |
| Comment  | Tags