top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

+1 vote
75 views
How can I get the absolute URL of a servlet/JSP page at runtime?
posted Oct 27, 2015 by Dominic

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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 java.net. 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(),
                                                             request.getServerName(),
                                                             request.getServerPort(),
                                                             file);
               out.println(URL.toString());
answer Oct 29, 2015 by Karthick.c
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...