Wednesday, August 12, 2009

How can get the entire URL of the current Servlet ?

The following code fragment will return the entire URL of the current Servlet

String currentFile = request.getRequestURI();
if (request.getQueryString() != null)
{
currentFile = currentFile + '?' + request.getQueryString();
}

URL currentURL = new URL(request.getScheme(),
request.getServerName(), request.getServerPort(), currentFile);

out.println(URL.toString());

1 comment: