Pages

Friday 9 December 2011

How to find latitude and longitude

The always helpful Tech-Recipes has come up with an ingenius way to find latitude and longitude values for any location using Google Maps.
You'll first need to look up an address (duh), but this trick only works if the address is centered (it's centered by default). So, moving the map around will not make this work. When the address you want to find latitude and longitude for is dead center, copy and paste this code into your browser bar:

javascript:void(prompt('',gApplication.getMap().getCenter()));

You'll get a popup with the coordinates. 

Get Latitude and Longitude values from Google Maps [Tech-Recipes ]

Friday 2 December 2011

Getting the Requesting URL in a Servlet

A servlet container breaks up the requesting URL into convenient components for the servlet. The standard API does not require the original requesting URL to be saved and therefore it is not possible to get the requesting URL exactly as the client sent it. However, a functional equivalent of the original URL can be constructed. The following example assumes the original requesting URL is:

public static String getUrl3(HttpServletRequest req) {
    String scheme = req.getScheme();             // http
    String serverName = req.getServerName();     // hostname.com
    int serverPort = req.getServerPort();        // 80
    String contextPath = req.getContextPath();   // /mywebapp
    String servletPath = req.getServletPath();   // /servlet/MyServlet
    String pathInfo = req.getPathInfo();         // /a/b;c=123
    String queryString = req.getQueryString();          // d=789

    // Reconstruct original requesting URL
    String url = scheme+"://"+serverName+":"+serverPort+contextPath+servletPath;
    if (pathInfo != null) {
        url += pathInfo;
    }
    if (queryString != null) {
        url += "?"+queryString;
    }
    return url;
}


http://www.exampledepot.com/egs/javax.servlet/GetReqUrl.html

 Origin url:
request.getHeader("Referer");