URL interpretation

The ServletContext and ServletRequest objects both contain methods to retrieve a RequestDispatcher instance. ServletContext methods require an absolute URL. ServletRequest methods can interpret a relative URL. Both URL types must follow these guidelines:

A ServletContext.getRequestDispatcher URL must begin with a forward slash (‘/’). If a ServletRequest.getRequestDispatcher URL begins with a forward slash, the servlet engine interprets it as an absolute URL. Otherwise, the servlet engine appends the relative URL to the current request’s URI path. For example, if the current request is /catalog/garden.html and the relative URL is sports.html, then the new URL is /catalog/sports.html.