Using relative URLs in sendRedirect()

Relative URLs come in two flavors: with or without a starting forward slash (“/”).

Imagine the client originally typed in: 
http://www.wickedlysmart.com/myApp/cool/bar.do

When the request comes into the servlet named “bar.do”, the servlet calls
sendRedirect() with a relative URL that does NOT start with a forward slash:

sendRedirect(“foo/stuff.html”);

The Container builds the full URL (it needs this for the “Location” header it
puts in the HTTP response) relative to the original request URL:

http://www.wickedlysmart.com/myApp/cool/foo/stuff.html

But if the argument to sendRedirect() DOES start with a forward slash:
sendRedirect(“/foo/stuff.html”);
The forward slash at the beginning means “relative to the root of this web Container”.

The Container builds the complete URL relative to the web Container itself, instead
of relative to the original URL of the request. So the new URL will be:
http://www.wickedlysmart.com/foo/stuff.html