An absolute URL is an URL which includes the scheme (e.g. http:
). A relative URL does not include the scheme and is thus dependent on the current context.
How to interpret a relative URL is a bit more complicated. It depends entirely on the context where the URL is been used. E.g. in a webbrowser, or in a servlet, or even in the local disk file system (java.io.File
and so on).
When talking in the servlet context, when a relative URL starts with /
, it will be relative to the context root (i.e. the root of the webcontent folder, there where the /WEB-INF
folder is and where all JSP files are been placed).
So when you want to forward the request to /WEB-INF/forums.jsp
, then you just specify that so:
request.getRequestDispatcher("/WEB-INF/forums.jsp").forward(request, response);
But when a relative URL doesn't start with /
, then it will be relative to the current request URL. So when the request URL is for example http://example.com/context/servlets/servletname and you use the relative URL forums.jsp
, then the following
request.getRequestDispatcher("forums.jsp").forward(request, response);
will actually point to http://example.com/context/servlets/forums.jsp