Mayumi Mayumi - 4 months ago 49
Java Question

Get URL of the request sender with HttpServletRequest

How do you get the source domain using HttpServletRequest?
Source domain is the requester's domain.

Thanks.

Answer

You could do either

// gets client (browser)'s hostname
String host = request.getRemoteHost(); 

OR

// get the server's domain name.
String domain = new URL(request.getRequestURL().toString()).getHost();