How can I get the absolute URL of a servlet/JSP page at runtime ?

Frank Steidinger

You can get all the necessary information to determine the URL from the request object. To reconstruct the absolute URL from the scheme, server name, port, URI and query string you can use the URL class from The following code fragment will determine your page's absolute URL:

String file = request.getRequestURI();
if (request.getQueryString() != null) {
   file += '?' + request.getQueryString();
URL reconstructedURL = new URL(request.getScheme(),

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact